简体   繁体   English

如何在鼠标悬停时停止动画?

[英]How to stop the animation on mouse hover?

I have a slider in my page, and I would like to make the animation to stop on mouse hover, and then to resume when the mouse is not there anymore. 我的页面上有一个滑块,我想使动画在鼠标悬停时停止,然后在鼠标不存在时继续播放。

I tried something with the .stop command but I didn't manage to make it work. 我使用.stop命令尝试了一些操作,但没有设法使其正常工作。 Can someone, please, help me? 有人可以帮帮我吗?

var $item = $('.carousel .item'); 
var $wHeight = $(window).height();
$item.eq(0).addClass('active');
$item.height($wHeight); 
$item.addClass('full-screen');

$('.carousel img').each(function() {
  var $src = $(this).attr('src');
  var $color = $(this).attr('data-color');
  $(this).parent().css({
    'background-image' : 'url(' + $src + ')',
    'background-color' : $color
  });
  $(this).remove();
});

$(window).on('resize', function (){
  $wHeight = $(window).height();
  $item.height($wHeight);
});

$('.carousel').carousel({
  interval: 2000,
  pause: "false"
});
$(this).stop(true);

stop()之前,请使用clearQueue()删除所有排队的动画。

Try to use this. 尝试使用这个。

$('.carousel').hover(function () { 
  $(this).carousel('pause') 
}, function () { 
  $(this).carousel('cycle') 
})

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

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