The second slideshow waiting for the first slideshow to finish(第二个幻灯片等待第一个幻灯片完成)
问题描述
The second slideshow waits for the first slideshow to finish IN THIS FIDDLE
Imagine if I have to have four slideshows in one page: slideshow one, slideshow two, slideshow three, and slideshow four.
The wrapper of all of the slideshows have the same class and has no ID, and the slideshows are run with a same script:
Actually, only one slideshow (the first) which is going to be shown in the page, while the rest are still hidden. If only the second link which refers to the second slideshow is clicked then the second slideshow will be shown in the page while at the same time the first slideshow will be hidden automatically.
If the second slideshow is shown in a wrapper DIV by clicking its link soon after you load the page, the second slideshow is blank with no content. The problem of its blank is because the second slideshow is waiting for the first slideshow to finish in sliding all the contents inside it.
Here is my html code:
<!--SLIDESHOW ONE-->
<div class="bigandsmall">
<div class="bigPicture">
<div class="easyzoom easyzoom--overlay">
<img src="Y29sb3VyL2JpZy9FdmFuLVBpY29uZS1UdXJ0bGVuZWNrLVN3ZWF0ZXItRHJlc3NfXzAxNjg4MjI0X2x1bmFfMS5qcGc="></div>
<div class="easyzoom easyzoom--overlay">
<img src="Y29sb3VyL2JpZy9FdmFuLVBpY29uZS1UdXJ0bGVuZWNrLVN3ZWF0ZXItRHJlc3NfXzAxNjg4MjI0X2x1bmFfMi5qcGc="></div>
</div>
<div class="smallPicture">
<img src="Y29sb3VyL3RodW1uYWlsL0V2YW4tUGljb25lLVR1cnRsZW5lY2stU3dlYXRlci1EcmVzc19fMDE2ODgyMjRfbHVuYV8xLmpwZw==">
<img src="Y29sb3VyL3RodW1uYWlsL0V2YW4tUGljb25lLVR1cnRsZW5lY2stU3dlYXRlci1EcmVzc19fMDE2ODgyMjRfbHVuYV8yLmpwZw==">
</div>
</div>
<!--END OF SLIDESHOW ONE-->
<!--SLIDESHOW TWO-->
<div class="bigandsmall">
<div class="bigPicture">
<div class="easyzoom easyzoom--overlay">
<img src="Y29sb3VyL2JpZy9FdmFuLVBpY29uZS1UdXJ0bGVuZWNrLVN3ZWF0ZXItRHJlc3NfXzAxNjg4MjI0X2x1bmFfMS5qcGc="></div>
<div class="easyzoom easyzoom--overlay">
<img src="Y29sb3VyL2JpZy9FdmFuLVBpY29uZS1UdXJ0bGVuZWNrLVN3ZWF0ZXItRHJlc3NfXzAxNjg4MjI0X2x1bmFfMi5qcGc="></div>
</div>
<div class="smallPicture">
<img src="Y29sb3VyL3RodW1uYWlsL0V2YW4tUGljb25lLVR1cnRsZW5lY2stU3dlYXRlci1EcmVzc19fMDE2ODgyMjRfbHVuYV8xLmpwZw==">
<img src="Y29sb3VyL3RodW1uYWlsL0V2YW4tUGljb25lLVR1cnRsZW5lY2stU3dlYXRlci1EcmVzc19fMDE2ODgyMjRfbHVuYV8yLmpwZw==">
</div>
</div>
<!--END OF SLIDESHOW TWO-->
Here is the script that I use to run the all slideshows:
var $el = $('.bigandsmall'),
// SETUP ////////
F = 600 , // Fade Time
P = 5000 , // Pause Time
C = 0 , // Counter / Start Slide# (0 based)
///////////////////
$sl = $('.bigPicture > div'),
$th = $('.smallPicture > img'),
N = $sl.length,
T = 10000;
$sl.hide().eq(C).show();
$th.eq(C).addClass('on');
// ANIMATION
function anim() {
$sl.eq(C%N).stop(1).fadeTo(F,1).siblings().fadeTo(F,0);
$th.removeClass('on').eq(C%N).addClass('on');
}
// AUTO ANIMATE
function autoAnim() {
T = setTimeout(function() {
C++;
anim(); // Animate
autoAnim(); // Prepare another iteration
}, P+F);
}
autoAnim(); // Start loop
// HOVER PAUSE
$el.hover(function(e) {
return e.type==='mouseenter'? clearTimeout( T ) : autoAnim();
});
// HOVER THUMBNAILS
$th.on('mouseenter', function() {
C = $th.index( this );
anim();
});
If you rewrite it as a plugin instead, you can manage each slideshow independently:
JSFiddle: http://jsfiddle.net/TrueBlueAussie/CH5YN/2/
Please note this is a just an example, not how you would normally write plugins cleanly. I did not attempt to cleanup the structure or code, just made it use separate instances and elements local to the container it is attached to. I styled them with a horrible yellow border so you can see the objects:
$.fn.slideThis = function () {
this.each(function () {
// Reference to current DOM object
var THIS = this;
// Current DOM object as jQuery object
var $this = $(this);
THIS.$sl = $this.find('.bigPicture > div'),
THIS.$th = $this.find('.smallPicture > img'),
THIS.N = THIS.$sl.length,
THIS.T = 10000;
THIS.C = 6;
THIS.$sl.hide().eq(THIS.C).show();
THIS.$th.eq(THIS.C).addClass('on');
THIS.P = 1000;
THIS.F = 1000;
$this.css({
border: "5px solid yellow"
});
// ANIMATION
THIS.anim = function () {
THIS.$sl.eq(THIS.C % THIS.N).stop(1).fadeTo(THIS.F, 1).siblings().fadeTo(THIS.F, 0);
THIS.$th.removeClass('on').eq(THIS.C % THIS.N).addClass('on');
}
// AUTO ANIMATE
THIS.autoAnim = function () {
THIS.T = setTimeout(function () {
THIS.C++;
THIS.anim(); // Animate
THIS.autoAnim(); // Prepare another iteration
}, THIS.P + THIS.F);
}
THIS.autoAnim(); // Start loop
// HOVER PAUSE
THIS.$sl.hover(function (e) {
return e.type === 'mouseenter' ? clearTimeout(THIS.T) : THIS.autoAnim();
});
// HOVER THUMBNAILS
THIS.$th.on('mouseenter', function () {
THIS.C = THIS.$th.index(this);
THIS.anim();
});
});
};
// Attach one of these to every matching element
$(".bigandsmall").slideThis();
I leave it to you read up on creating jQuery plugins and cleanup the code :)
这篇关于第二个幻灯片等待第一个幻灯片完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:第二个幻灯片等待第一个幻灯片完成


- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01