jquery监听向上向下滑动,滑动执行操作
var beforeScrollTop = $(window).scrollTop();
$(window).on("scroll", function (event) {
var scrollTop = $(window).scrollTop();
var delta = false;
var afterScrollTop = $(window).scrollTop();
var delta = afterScrollTop - beforeScrollTop;
var videoW = $('.video-wrap video').width();
var videoH = $('.video-wrap video').height();
if (delta === 0) {
return false;
}
if (delta > 0) {
if (video_height >= videoH && videoH > 90) {
var shrinkH = videoH - delta;
var shrinkW = shrinkH / video_height;
$('.video-wrap video').height(shrinkH).width(`${shrinkW * 100}%`);
} else if (videoH < 90) {
$('.video-wrap video').height(90).width("25%");
}
} else {
if (video_height > videoH) {
var shrinkH = videoH - delta;
var shrinkW = shrinkH / video_height;
$('.video-wrap video').height(shrinkH).width(`${shrinkW * 100}%`);
} else {
$('.video-wrap video').height(video_height).width("100%");
}
}
beforeScrollTop = afterScrollTop;
});