Image: Dominik Szoboszlai proposed to his girlfriend

The Intricacies of a Video Container Animation

Welcome to the bizarre and wonderful world of JavaScript and jQuery! Today, we dive into the fascinating (and slightly baffling) code that governs a video container on the web. Which, if we’re honest, is about as exhilarating as watching paint dry. But hey, we’re here to spice it up!

Now, let’s get our hands dirty. First thing’s first – the code checks if the #m4sport_lead_video_containerBig exists. If it doesn’t, boom! No need to fret. It simply returns, like a cat that decided you’ve touched it too much. You know the type, right?

The Basics

The code then trots along to define the dimensions and position of the video container.


var sourceVideoContainer = {
    'position': jQuery('#m4sport_lead_video_container').css('position'),
    'left'    : jQuery('#m4sport_lead_video_container').position().left,
    'top'     : jQuery('#m4sport_lead_video_container').position().top,
    'width'   : jQuery('#m4sport_lead_video_container').width(),
    'height'  : jQuery('#m4sport_lead_video_container').height(),
};

Right here, we’ve got ourselves a nice little object that tracks everything about where our video is situated. It’s like a real estate agent for video containers: “It’s got a great view, spacious for all your scrolling – and the size? Perfect!”

The Resize Saga

Now, let’s talk about the resize functionality. This is when the drama unfolds!


jQuery(window).resize(function() {
    widthOfStickiedVideo = jQuery('#articleRecommenderWidget_contentVideoSmall').attr('data-widthsource');
    widthOfStickiedVideo = jQuery(widthOfStickiedVideo).first().width();
    jQuery('#articleRecommenderWidget_contentVideoSmall').width(widthOfStickiedVideo).height(widthOfStickiedVideo / 1.6);
});

If you thought resizing was straightforward, think again! Our friends at jQuery want to ensure that when you resize that window, the video element adjusts more accurately than your uncle’s waistline during the holidays. It attempts to maintain that same chic aspect ratio, turning ugly when it doesn’t. We’ve all been there…

The Interval Interlude

What follows next is a riveting setInterval function that repetitively checks on the player like a worried parent.


setInterval(function() {
    let player = jQuery(document).find('.mtva-player').prop('mtva_player');
    return;
    console.clear();
    console.log(player);
    console.log(player.element);
    console.log(jwplayer());
}, 1000);

This function clears the console and logs player information every second. It’s like waiting for a text from your crush, except it keeps coming without you even knowing if they care. Spoiler alert: they probably don’t!

Scroll Drama

But hold on, there’s more drama! The script also checks if the user is scrolling:


jQuery(window).scroll(function() {
    if (jQuery(this).scrollTop() > parseInt(jQuery('#articleRecommenderWidget_contentVideoSmall').attr('data-tresholdy'))) {
        scrolling = 1;
    } else {
        scrolling = -1;
    }
});

This profound piece of code determines whether something is going up or down, much like a poorly managed relationship. It checks the scroll position against a threshold before declaring whether the video needs to move up or down. The stakes are high!

Final Remarks

Finally, there’s love in the air as the video slides like a dancer at a wedding. With animations lasting three seconds, you might just grab the popcorn. The code embodies pure elegance – if elegance were a video that’s constantly moving at the whims of users who may or may not be paying attention.

In conclusion, the animated video container is a marvel of modern web development. It juggles dimensions, positions, and user interactions all while pretending to be casual about it. So, next time you’re watching that video, remember the silent ballet of JavaScript and jQuery happening behind the scenes, and give it a silent round of applause – if you have any pity left after all that scrolling and resizing!

Thank you for joining this deep-dive analysis, and may your code always run smoothly!

*/
if (jQuery(‘#m4sport_lead_video_containerBig’).length === 0)
{
return;
}
var sourceVideoContainer = {
‘position’: jQuery(‘#m4sport_lead_video_container’).css(‘position’),
‘left’ : jQuery(‘#m4sport_lead_video_container’).position().left,
top‘ : jQuery(‘#m4sport_lead_video_container’).position().top,
‘width’ : jQuery(‘#m4sport_lead_video_container’).width(),
‘height’ : jQuery(‘#m4sport_lead_video_container’).height(),
};
var widthOfStickiedVideo;
jQuery(window).resize(function() {
widthOfStickiedVideo = jQuery(‘#articleRecommenderWidget_contentVideoSmall’).attr(‘data-widthsource’);
widthOfStickiedVideo = jQuery(widthOfStickiedVideo).first().width();
jQuery(‘#articleRecommenderWidget_contentVideoSmall’).width(widthOfStickiedVideo).height(widthOfStickiedVideo / 1.6);
});
jQuery(window).resize();

setInterval(function() {
let player = jQuery(document).find(‘.mtva-player’).prop(‘mtva_player’);
return;
console.clear();
console.log(player);
console.log(player.element);
console.log(jwplayer());
}, 1000);

setInterval(function() {
if (!isMoving)
{
switch(scrolling)
{
case -1 : // felküldené
if (!videoIsUp)
{
scrolling = 0;
isMoving = true;
jQuery(‘#m4sport_lead_video_container’)
.css({‘position’: sourceVideoContainer.position})
.animate(
{
‘left’: sourceVideoContainer.left,
‘top’: sourceVideoContainer.top,
‘width’: sourceVideoContainer.width,
‘height’: sourceVideoContainer.height
},
3000,
function() {
// felért
videoIsUp = true;
isMoving = false;
}
);
}
break;
case 1 : // leküldené
if (videoIsUp)
{
scrolling = 0;
isMoving = true;
jQuery(‘#m4sport_lead_video_container’)
.css({‘position’: ‘fixed’})
.offset({‘top’: parseInt(jQuery(‘#articleRecommenderWidget_contentVideoSmall’).attr(‘data-targettop’))+’px’})
.width(parseInt(jQuery(‘#m4sport_lead_video_container’).width()) / 2)
.height(jQuery(‘#articleRecommenderWidget_contentVideoSmall’).height())
.animate({
‘left’ : jQuery(‘#articleRecommenderWidget_contentVideoSmall’).position().left,
‘top’ : parseInt(jQuery(‘#articleRecommenderWidget_contentVideoSmall’).attr(‘data-targettop’)),
‘width’ : jQuery(‘#articleRecommenderWidget_contentVideoSmall’).width(),
‘height’: jQuery(‘#articleRecommenderWidget_contentVideoSmall’).height(),
},
3000,
function() {
// leért
videoIsUp = false;
isMoving = false;
}
);
}
break;
}
}
}, 100);

jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > parseInt(jQuery(‘#articleRecommenderWidget_contentVideoSmall’).attr(‘data-tresholdy’)))
{
scrolling = 1;
}
else
{
scrolling = -1;
}
});
});

Share:

Facebook
Twitter
Pinterest
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

On Key

Related Posts