繁体   English   中英

jquery悬停和线旋转动画

[英]jquery hover and line rotate animation

https://jsfiddle.net/eunjin/zasmLkzm/4/

$('#menu_bar').hover(function(){
    $('.line1').stop().animate({borderSpacing:45},{
        step: function(now,fx){
            $(this).css('-webkit-transform','rotate('+now+'deg)'); 
            $(this).css('-moz-transform','rotate('+now+'deg)');
            $(this).css('transform','rotate('+now+'deg)');
        },
        duration:'slow'
    },'linear');
    $('.line3').stop().animate({borderSpacing:-45},{
        step: function(now,fx){
            $(this).css('-webkit-transform','rotate('+now+'deg)'); 
            $(this).css('-moz-transform','rotate('+now+'deg)');
            $(this).css('transform','rotate('+now+'deg)');
        },
        duration:'slow'
    },'linear');
}, function(){
    $('.line1').stop().animate({borderSpacing:0},{
        step: function(now,fx){
            $(this).css('-webkit-transform','rotate('+now+'deg)'); 
            $(this).css('-moz-transform','rotate('+now+'deg)');
            $(this).css('transform','rotate('+now+'deg)');
        },
        duration:'slow'
    },'linear');
    $('.line3').stop().animate({borderSpacing:0},{
        step: function(now,fx){
            $(this).css('-webkit-transform','rotate('+now+'deg)'); 
            $(this).css('-moz-transform','rotate('+now+'deg)');
            $(this).css('transform','rotate('+now+'deg)');
        },
        duration:'slow'
    },'linear');
});

我显示某人的代码并使用它但它不会旋转 - 代码当我键入+45时,它会旋转悬停并取消悬停但键入-45它会旋转悬停但是徘徊,它不会旋转

对不起我的英语我不会使用英语到我的母语

它正在发生,因为在uni悬停部分的jQuery animate函数中,borderSpacing的初始值为0,你将为0.你可以使用console.log对step函数进行验证,以便now打印出来并使用fx 不要使用borderSpacing因为它指向一个有效的CSS属性,该属性不应该是负数(来源 - http://www.w3schools.com/cssref/pr_border-spacing.asp查看属性值标题,值长度 。)。

只需使用像rotate这样成功的伪属性 -

https://jsfiddle.net/zasmLkzm/10/

希望这可以帮助。

暂无
暂无

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

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