鼠标过度褪色时淡出效果

时间:2015-10-16 12:59:27

标签: javascript mouseover mouseout

我需要在鼠标悬停和输出时添加淡化效果。

$(document).ready(function(){
    $("#txtchange").mouseover(function (){
        $('#txtchange').text("My New Txt");
    });
    $("#txtchange").mouseout(function (){
        $('#txtchange').text("Old Txt");
    });
});

2 个答案:

答案 0 :(得分:0)

您可以使用jquery函数fadeIn()

$(document).ready(function(){
    $("#txtchange").mouseover(function (){
        $('#txtchange').text("My New Txt").fadeIn( "slow" );
    });
    $("#txtchange").mouseout(function (){
        $('#txtchange').text("Old Txt").fadeIn( "slow" );
    });
});

答案 1 :(得分:0)

尝试使用以下代码

    $(document).ready(function(){    
       $("#txtchange").mouseover(function (){
           $("#txtchange").fadeOut(function() {
             $(this).text("My New Txt").fadeIn();
           });
       });    
       $("#txtchange").mouseout(function (){
          $("#txtchange").fadeOut(function() {
            $(this).text("Old Txt").fadeIn();
          });   
       });    
  });