如何改变按钮时,新的视频滚动到视图上的页面



在这个页面http://kimcolemanprojects.com/djangolive_1.html有五个视频。

当你点击每个视频下一个视频滚动到视图与jQuery。

由于这种jQuery效果,我不得不禁用视频控件。所以我决定在每个视频的左边放一个播放/暂停按钮。

然而,我现在需要一些帮助,使一个脚本,将改变按钮时,每个新视频滚动到视图。我有一个脚本,可以在不同的视频滚动到视图时改变标题,也在每个视频的左侧,请参阅下面的脚本。

$(window).load(function(){
// Scroll to titles on click
$('a').on('click', function() {
var target = $(this).attr('href');
$('html,body').animate({
scrollTop: $(target).offset().top
}, 'slow');
return false;
});
// jQuery `inView`-expression
$.extend($.expr[':'], {
inView: function(el) {
var width = $(el).width(),
height = $(el).height(),
offset = $(el).offset(),
vp_dimensions = {
height: $(window).height(),
width: $(window).width()
},
y_offset = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop),
x_offset = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
return (
offset.top < (y_offset + vp_dimensions.height) && offset.left < (x_offset + vp_dimensions.width) && (offset.top + height) > y_offset && (offset.left + width) > x_offset);
}
});
// Change the titles on scroll
$(window).scroll(function() {
$('li').each(function() {
var self = $(this),
title = self.find('video').attr('title');
if (self.is(':inView')) {
$('#title').find('h2').text(title);
}
});
}).scroll();
});

感谢您的宝贵时间

安吉拉

下面的代码实现了我想要的更多,它不仅使按钮对应于滚动到视图的视频,它也暂停视频时滚动出视图,当视频已经完成播放时,它滚动下一个进入视图并自动播放。感谢jQuery论坛上的jakecigar。

$.extend($.expr[':'], { // jQuery `inView`-expression
inView: function (el) {
var width = $(el).width(),
height = $(el).height(),
offset = $(el).offset(),
vp_dimensions = {
height: $(window).height(),
width: $(window).width()
},
y_offset = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop),
x_offset = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
return(
offset.top < (y_offset + vp_dimensions.height) && offset.left < (x_offset + vp_dimensions.width) && (offset.top + height) > y_offset && (offset.left + width) > x_offset);
}
});
var video;
$(function (){
video=$('video:first').get(0)
$('a').on('click', function () {
var target = $(this).attr('href');
$('html,body').animate({
scrollTop: $(target).offset().top
}, 'slow')
return false;
});
$('video').on('ended',function(){
$(this).parents('a').click()
setTimeout(vidplay,1000)
})
});
$(window).scroll(function () {
$('video:not(:inView)').each(function () {
this.pause()
})
video = $('video:inView:last').get(0)
if(video) $('#title').find('h2').text(video.title)
}).scroll();
function vidplay() {
if(video.paused) {
video.play();
$('#play').text("||");
} else {
video.pause();
$('#play').text(">");
}
}
function percent(){
return (video.currentTime/video.duration*100).toFixed(0)+'%'
}
function restart() {
video.currentTime = 0;
}
function skip(value) {
video.currentTime += value;
} 

相关内容

最新更新