Jquery animate. Display none css is not changing

前端 未结 2 1906
执笔经年
执笔经年 2020-12-21 12:03

In the first load of the page the image have to display:none. But the problem is, when I put display none, the animate function is not working and I already

相关标签:
2条回答
  • 2020-12-21 12:59
    $(this).css({'display':'block'}); == $(this).show();
    $(this).stop().animate({"opacity": "0"}, 300); == $(this).fadeOut(300);
    

    etc

    Change

    $("img.fade").hover(
    

    to

    $("img.fade").hide().hover(
    

    /E:

    And remove style

    0 讨论(0)
  • 2020-12-21 13:03

    If something's hidden you can't hover over it, since it occupies no space in the page. Instead set it's opacity to 0 initially. Remove your CSS and you can do this:

    $(document).ready(function() {
        $("img.fade").hover(function() {
            $(this).stop().animate({ opacity: 1 }, 300);
        }, function() {
            $(this).stop().animate({ opacity: 0 }, 300);
        }).css({ opacity: 0 });
    });
    

    You can test it out here. Or, remove .css({ opacity: 0 }); and change your CSS to this:

    img.fade { opacity: 0; filter: alpha(opacity=0); }
    

    You can test that version here.

    0 讨论(0)
提交回复
热议问题