Skip to content

Instantly share code, notes, and snippets.

@al5dy
Created July 8, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save al5dy/60214756b9f7130a0f7bf97fc4efc7cf to your computer and use it in GitHub Desktop.
Save al5dy/60214756b9f7130a0f7bf97fc4efc7cf to your computer and use it in GitHub Desktop.
"Размазываем" фоновое видео в зависимости от соотношения сторон
vimeoSettings : function () {
var wa = 16, // Соотношение сторон
ha = 9, // Соотношение сторон
$videoBlock = $('.vimeo-video'), // Блок внутри которого лежит iframe
od = $videoBlock.width()/$videoBlock.height(),
vd = wa/ha,
nvh = (od/vd)*100,
nvw = (vd/od)*100;
if (od>vd)
$videoBlock.find('iframe').css({height:nvh+'%', width:'100%', top:-(nvh-100)/2+'%',left:'0px',position:'absolute'});
else
$videoBlock.find('iframe').css({width:nvw+'%', height:'100%', left:-(nvw-100)/2+'%',top:'0px',position:'absolute'});
},
@al5dy
Copy link
Author

al5dy commented Jan 21, 2021

Also:

vcResizeVideoBackground : function ($element) {

        if($element.length > 0) {
            var iframeW, iframeH, marginLeft, marginTop, containerW = $element.innerWidth(), containerH = $element.innerHeight();
            containerW / containerH < 16 / 9 ? (iframeW = containerH * (16 / 9), iframeH = containerH, marginLeft = -Math.round((iframeW - containerW) / 2) + 'px',
                marginTop = -Math.round((iframeH - containerH) / 2) + 'px', iframeW += 'px', iframeH += 'px') : (iframeW = containerW, iframeH = containerW * (9 / 16),
                marginTop = -Math.round((iframeH - containerH) / 2) + 'px', marginLeft = -Math.round((iframeW - containerW) / 2) + 'px', iframeW += 'px', iframeH += 'px'),
                $element.find('iframe').css({maxWidth: '1000%', marginLeft: marginLeft, marginTop: marginTop, width: iframeW, height: iframeH});
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment