繁体   English   中英

用鼠标离开反转jquery动画

[英]Reversing jquery animation with mouse leave

这真的让我感到沮丧,因为这是一个简单的问题,我知道当有人给哈哈的1行回答时,我自己会脸红。 无论如何,我在mouseenter片段上有以下内容

$("nav#primary ul li").mouseenter(function(){
    $(this).find('ul:first').stop(true, true).animate({
              height: ['toggle', 'swing'],
              opacity: 'toggle'
          }, 300, 'linear');
  });

我的问题是,在鼠标离开原边后,如何反转动画的效果?

$("nav#primary ul li").mouseenter(function(){
    //your code for mouseenter
},function(){
    //your code for mouseleave
});

如果我正确理解了您的问题,则当鼠标进入一个元素时,您正在设置动画和不透明度,并在离开时恢复到原始状态。

$( "av#primary ul li" ).hover(
    function() {  // on mouse enter
        // save the original values
        var h = $(this).css('height');
        var o = $(this).css('opacity');
        $(this).attr('data-Oheight',h).attr('data-Oopacity',o);
        // do your animation here
    }, function() {     // on mouse leave
        // retrive the original values
        var h = $(this).attr('data-Oheight');
        var o = $(this).attr('data-Oopacity');
        // revert back
        //do your animation to revert back
    }
);

但是,话虽如此,但是还有GreenSock的TweenMax工具。 这些动画要求非常方便。 让我知道您是否需要了解更多。

暂无
暂无

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

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