slider ,该行在 setTimeout 之前运行,并在鼠标悬停后执行脚本一次,直到所有幻灯片完成
你好,我有这个 html
<div class="slideListHolder clearfix">
<div class="cntBoxes">
<div class="mainBox" id="list-1">
<img src="img/m1.jpg"width="200" height="400" alt="" />
<a class="link" target="_blank" href="http://test.euwebstudio.jp/ntt/careerup/premium/index2.html">詳細はこちら</a>
</div>
<div class="box id-1">
<img src="img/img1.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-2">
<img src="img/img6.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-3">
<img src="img/img11.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-4">
<img src="img/img16.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-5">
<img src="img/img21.jpg"width="200" height="400" alt=""/>
</div>
</div>
<div class="cntBoxes">
<div class="mainBox" id="list-2">
<img src="img/m2.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-1">
<img src="img/img2.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-2">
<img src="img/img7.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-3">
<img src="img/img12.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-4">
<img src="img/img17.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-5">
<img src="img/img22.jpg"width="200" height="400" alt=""/>
</div>
</div>
</div>
和这个 js
var cntBoxes='.slideListHolder .cntBoxes';
var time = 300;
$(cntBoxes).mouseover(function() {
if(!$(this).parent('div').hasClass('dc') && !$(this).parent('div').hasClass('over')){
$(cntBoxes).parent('div').addClass('over');
var elem = $(this);
pieces=elem.children('.mainBox').attr('id').split('list-');
if (typeof pieces[1] !== "undefined") {
$(cntBoxes).children('.mainBox').each(function(){
var $this=$(this)
setTimeout( function(){
$this.fadeOut('fast',function(){
var showId='.id-'+pieces[1];
$this.parent('div').children(showId).fadeIn('fast');
});
},time)
time += 300;
});
$(cntBoxes).parent('div').addClass('dc');
$(cntBoxes).parent('div').removeClass('over');
}
}
})
$(cntBoxes).click(function() {
if($(this).parent('div').hasClass('dc')){
$(cntBoxes).children('.box:visible').each(function(){
$(this).fadeOut('slow',function(){
$(this).parent('div').children('.mainBox').fadeIn('slow');
});
});
$(cntBoxes).parent('div').removeClass('dc');
}
});
该怎么做,这一行 $(cntBoxes).parent('div').removeClass('over');
,在 setTimeout( function() 之后{
,以及如何将鼠标悬停在所有幻灯片都完成之前,此脚本正在执行多次,非常感谢,如果解释不太清楚,抱歉。
Hi i have this html
<div class="slideListHolder clearfix">
<div class="cntBoxes">
<div class="mainBox" id="list-1">
<img src="img/m1.jpg"width="200" height="400" alt="" />
<a class="link" target="_blank" href="http://test.euwebstudio.jp/ntt/careerup/premium/index2.html">詳細はこちら</a>
</div>
<div class="box id-1">
<img src="img/img1.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-2">
<img src="img/img6.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-3">
<img src="img/img11.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-4">
<img src="img/img16.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-5">
<img src="img/img21.jpg"width="200" height="400" alt=""/>
</div>
</div>
<div class="cntBoxes">
<div class="mainBox" id="list-2">
<img src="img/m2.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-1">
<img src="img/img2.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-2">
<img src="img/img7.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-3">
<img src="img/img12.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-4">
<img src="img/img17.jpg"width="200" height="400" alt=""/>
</div>
<div class="box id-5">
<img src="img/img22.jpg"width="200" height="400" alt=""/>
</div>
</div>
</div>
And this js
var cntBoxes='.slideListHolder .cntBoxes';
var time = 300;
$(cntBoxes).mouseover(function() {
if(!$(this).parent('div').hasClass('dc') && !$(this).parent('div').hasClass('over')){
$(cntBoxes).parent('div').addClass('over');
var elem = $(this);
pieces=elem.children('.mainBox').attr('id').split('list-');
if (typeof pieces[1] !== "undefined") {
$(cntBoxes).children('.mainBox').each(function(){
var $this=$(this)
setTimeout( function(){
$this.fadeOut('fast',function(){
var showId='.id-'+pieces[1];
$this.parent('div').children(showId).fadeIn('fast');
});
},time)
time += 300;
});
$(cntBoxes).parent('div').addClass('dc');
$(cntBoxes).parent('div').removeClass('over');
}
}
})
$(cntBoxes).click(function() {
if($(this).parent('div').hasClass('dc')){
$(cntBoxes).children('.box:visible').each(function(){
$(this).fadeOut('slow',function(){
$(this).parent('div').children('.mainBox').fadeIn('slow');
});
});
$(cntBoxes).parent('div').removeClass('dc');
}
});
how to do , this line $(cntBoxes).parent('div').removeClass('over');
, after setTimeout( function(){
, and how is possible mouse over until all slides are finished , this script is executing multiple times . Thank You A LOT , Sorry if Explanation is not so clear
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题你早就解决了。对我来说并不重要,也许其他人看到这个并使用。首先,在java脚本中,定时器函数像ajax函数一样是异步的。它们以不同的步骤开始,这意味着您的代码将在 setTimeout 函数之后立即继续,而无需等待它结束/返回。
有一些方法可以使用队列、TimeoutChain ...
你应该看这里
我知道这不是一个好的答案,但我认为它可以为问题提供很好的线索。
You would have already solved this question. doesn't matter for me, maybe one another see this and use. First, in java script, timer functions are asynchronous like ajax functions. They are started at different treads It means your code will be continuing right after your setTimeout function without waiting it to be ended/returned.
There are some ways to do it with using queues, TimeoutChain ...
you should look here
I know its not a good answer but i think it could give good clues about the problem.