我有一个问题,我不知道如何解决它。
我想从第一个div滑动到第二个div然后自动播放电影,当我滑到第三个div时停止它。
以下是代码:
(function($) {
$.backgroundVideo = function(el, options) {
var defaults = {
videoid: "video_background"
}
var plugin = this;
plugin.settings = {}
var init = function() {
plugin.settings = $.extend({}, defaults, options);
plugin.el = el;
buildVideo();
}
var buildVideo = function () {
var html = '';
html += '<video id="'+plugin.settings.videoid+'" autoplay="autoplay" loop="loop"';
html += 'style="display:none;position:relative;top:0;left:0;bottom:0;right:0;z-index:-100;width:100%;height:100%;">';
for(var i=0; i < plugin.settings.types.length; i++) {
html += '<source src="'+plugin.settings.path+plugin.settings.filename+'.'+plugin.settings.types[i]+'" type="video/'+plugin.settings.types[i]+'" />';
}
html += 'bgvideo</video>';
plugin.el.prepend(html);
plugin.videoEl = document.getElementById(plugin.settings.videoid);
plugin.$videoEl = $(plugin.videoEl);
plugin.$videoEl.fadeIn(0);
setProportion();
}
var setProportion = function () {
var proportion = getProportion();
plugin.$videoEl.width(proportion*plugin.settings.width);
plugin.$videoEl.height(proportion*plugin.settings.height);
if (typeof plugin.settings.align !== 'undefined') {
centerVideo();
}
}
var getProportion = function () {
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var windowProportion = windowWidth / windowHeight;
var origProportion = plugin.settings.width / plugin.settings.height;
var proportion = windowHeight / plugin.settings.height;
if (windowProportion >= origProportion) {
proportion = windowWidth / plugin.settings.width;
}
return proportion;
}
var centerVideo = function() {
var centerX = (($(window).width() >> 1) - (plugin.$videoEl.width() >> 1)) | 0;
var centerY = (($(window).height() >> 1) - (plugin.$videoEl.height() >> 1)) | 0;
if (plugin.settings.align == 'centerXY') {
plugin.$videoEl.css({ 'left': centerX, 'top': centerY });
return;
}
if (plugin.settings.align == 'centerX') {
plugin.$videoEl.css('left', centerX);
return;
}
if (plugin.settings.align == 'centerY') {
plugin.$videoEl.css('top', centerY);
return;
}
}
init();
$(window).resize(function() { setProportion(); });
plugin.$videoEl.bind('ended', function(){ this.play(); });
}
})(jQuery);
答案 0 :(得分:0)
使用某些事件处理程序,如onFocusIn或onFoucsOut。