jQuery循环';摧毁';忽略命令(和所有其他命令)
我在jQuery循环中遇到了一个问题,就是忽略所有命令(destory、stop等)。在这一页上还有很多其他的事情,这可能是有帮助的,但是我不确定有多少示例代码太多了 简而言之,我有两个同步的幻灯片,在页面加载时初始化,当点击“.video trigger”时,循环实例应该被销毁。但点击后,cycle会继续循环(并掩盖应该取代它的视频) 我尝试了我能想到的所有可能的场景,试图找到源代码——删除所有其他javascript(只剩下循环和销毁点击事件),只尝试调用和销毁两个幻灯片中的一个(而不是两个),在单独的包装器中调用它们。我甚至删除了这两个循环实例,并在页面的另一个完全不同的部分创建了一个超级简单的“测试”循环和单击事件,而且这个循环也不能被销毁。不知道我错过了什么 这里使用的另一个jQuery插件是videojs,如果这很重要的话 这是所有的脚本,除了一个与视频无关的fancybox。如果它能帮助包括一切,让我知道,但我想我可能已经包括太多了jQuery循环';摧毁';忽略命令(和所有其他命令),jquery,jquery-cycle,Jquery,Jquery Cycle,我在jQuery循环中遇到了一个问题,就是忽略所有命令(destory、stop等)。在这一页上还有很多其他的事情,这可能是有帮助的,但是我不确定有多少示例代码太多了 简而言之,我有两个同步的幻灯片,在页面加载时初始化,当点击“.video trigger”时,循环实例应该被销毁。但点击后,cycle会继续循环(并掩盖应该取代它的视频) 我尝试了我能想到的所有可能的场景,试图找到源代码——删除所有其他javascript(只剩下循环和销毁点击事件),只尝试调用和销毁两个幻灯片中的一个(而不是两个
jQuery(document).ready(function($){
/// fading background images and video trigger
$('#background-image-wrapper,#trigger-fade').cycle();
// handle videos
$('.video-trigger').click(function() {
$('#background-image-wrapper,#trigger-fade').cycle('destroy');
var vidName = $(this).attr('id');
var vidID = 'video_' + vidName;
$('#background-image-wrapper').append('<div id="vid-cont" class="video-container"></div>');
$('#vid-cont').append('<video id="' + vidID + '" class="video-js vjs-default-skin" preload="auto" data-setup="{}">' +
'<source src="http://domain.com/wp-content/themes/sapporo/v/sapporo-'+ vidName +'.mp4" type="video/mp4">' +
'<source src="http://domain.com/wp-content/themes/sapporo/v/sapporo-'+ vidName +'.ogv" type="video/ogg">' +
'<source src="http://domain.com/wp-content/themes/sapporo/v/sapporo-'+ vidName +'.webm" type="video/webm">' +
'</video>');
//alert(vidID);
_V_(vidID).ready(function(){
var myPlayer = this;
var aspectRatio = 9/16;
function resizeVideoJS(){
//var width = document.getElementById(myPlayer.id).parentElement.offsetWidth; // Get the parent element's actual width -- this wasn't working with lower versions of FF
var width = document.getElementById('vid-cont').offsetWidth; // Get the parent element's actual width
myPlayer.width(width).height( width * aspectRatio ); // Set width to fill parent element, Set height
}
resizeVideoJS(); // Initialize the function
window.onresize = resizeVideoJS; // Call the function on resize
$('#trigger-fade').fadeOut();
$('#video-controls').fadeIn();
$('.video-container').css('left', '0');
myPlayer.volume(0);
myPlayer.play(); //start playing the video
var endedEvent = function(){
$('#video-controls').fadeOut(function(){ $('#trigger-fade').fadeIn(); });
$('.video-container').css('left', '-9999em');
$('.background-image').fadeIn('slow');
};
myPlayer.addEvent("ended", endedEvent);
$('#pause-video').click(function(){
myPlayer.pause();
$(this).fadeOut(function(){ $('#play-video').fadeIn(); });
});
$('#play-video').click(function(){
myPlayer.play();
$(this).fadeOut(function() { $('#pause-video').fadeIn(); });
});
$('#mute-video').click(function(){
myPlayer.volume(0);
$(this).fadeOut(function(){ $('#unmute-video').fadeIn(); });
});
$('#unmute-video').click(function(){
myPlayer.volume(.7);
$(this).fadeOut(function() { $('#mute-video').fadeIn(); });
});
$('#close-video').click(function(){
myPlayer.pause();
$('#video-controls').fadeOut(function(){ $('#trigger-fade').fadeIn(); });
$('.video-container').css('left', '-9999em');
$('.background-image').fadeIn('slow');
});
});
});
});
然后,在单击事件中使用此选项:
$('#background-image-wrapper,#trigger-fade').cycle('destroy');
或
然后,它不再销毁或暂停,而是开始一个新的循环实例,就好像“销毁/暂停”不存在一样。我有一个类似的问题,对我来说,解决方案是将循环存储在一个变量中,并调用此变量来销毁它。像这样:
var mycycle = $('#background-image-wrapper,#trigger-fade').cycle();
...
mycycle.cycle('destroy');
不确定你是否还需要这个,但也许有人会。我也有同样的问题。此处似乎完全忽略了“销毁”命令:
我只希望一次运行一个幻灯片,但由于“销毁”命令不起作用,它会继续运行隐藏的幻灯片。控制台中会出现错误吗?一个简单的
$(“#背景图像包装,#触发淡入”).hide()
(只是为了看看你的选择器是否正确)可以工作吗?问题很好,但没有,控制台中没有错误,是的,hide可以工作(选择器正确)。
$('#background-image-wrapper,#trigger-fade').cycle('pause');
var mycycle = $('#background-image-wrapper,#trigger-fade').cycle();
...
mycycle.cycle('destroy');