简体   繁体   English

jQuery toggle('slide')仅滑动一次

[英]Jquery toggle('slide') only slides once

I am very new to jquery so please forgive me in advance if my question is too basic. 我对jquery非常陌生,所以如果我的问题太基础了,请提前原谅我。 I am having some problems with a hover slide effect that seems to be a mixture of CSS and jquery issue. 我在悬停幻灯片效果上遇到了一些问题,这似乎是CSS和jquery的混合问题。 When i hover over the image it slides over to the end of the image perfectly well the first time, but then it seems that the hover effect only slides half way from under the first element the second time, instead of starting from the image sliding over the the end. 当我将鼠标悬停在图像上时,它第一次会很好地滑到图像末尾,但是第二次看来,悬停效果仅从第一个元素下方滑了一半,而不是从图像滑过最后。

I have tried many other possibilities for this but so far have had no luck, i would be very grateful if someone can point me in the right direction :) 我为此尝试了许多其他可能性,但到目前为止还没有运气,如果有人可以向我指出正确的方向,我将不胜感激:)

An example of what i am trying to achieve can be found here 我要实现的目标的示例可以在此处找到

http://jsfiddle.net/robolist/rK4GD/ http://jsfiddle.net/robolist/rK4GD/

$('.proimg').hover(function(event) {
      $('.boxcaption',this).stop().toggle( 'slide' );
}).on('mouseleave',function(event) {
      $('.boxcaption',this).stop().toggle( 'slide' )});

Many thanks in advance 提前谢谢了

When you use toggle on hover, you don't need to do the the mouseleave event. 使用悬停切换时,不需要执行mouseleave事件。 Also note that stop takes to boolean parameters, first for clear queue, second for jump to end: 还要注意,stop使用布尔值参数,第一个用于清除队列,第二个用于跳转到结束:

Just do: 做就是了:

$('.proimg').hover(function(event) {
    $('.boxcaption',this).stop(true, true).toggle( 'slide' );
});

Fiddle: http://jsfiddle.net/rK4GD/10/ 小提琴: http : //jsfiddle.net/rK4GD/10/

See: http://api.jquery.com/stop/ 请参阅: http//api.jquery.com/stop/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM