简体   繁体   English

(jQuery&JavaScript)动画返回原始状态

[英](jQuery & JavaScript) animate goes back to orgininal state

So I have this code: 所以我有这段代码:

$(document).ready(function(){

    $('#nexButton').mouseenter(function(){
        $('#nexButton').stop().animate({opacity: '1'},'fast'); 
            $('#nexButton').mouseleave(function(){
                $('#nexButton').stop().animate({opacity: '0.7'},'fast'); 
            });
    });

     $('#bacButton').mouseenter(function(){
        $('#bacButton').stop().animate({opacity: '1'},'fast'); 
            $('#bacButton').mouseleave(function(){
                $('#bacButton').stop().animate({opacity: '0.7'},'fast'); 
            });
    });

});

in my javascript and with the nexButton it runs perfect but with the bacbutton it just go back to 0.7 opacity while I'm still on the button?! 在我的JavaScript中,使用nexButton可以完美运行,但是使用bacbutton可以回到0.7不透明度,而我仍在使用按钮? What did I do wrong? 我做错了什么?

You can try this: 您可以尝试以下方法:

$(document).ready(function(){
    $('#nexButton, #bacButton')
      .on('mouseenter', function(){
          $(this).animate({opacity: '1'}, 'fast'); 
      })
      .on('mouseleave', function(){
          $(this).animate({opacity: '0.7'},'fast'); 
      });
});

Here is the FIDDLE . 这是FIDDLE

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

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