开发者

Problem Slide-In/Out JQuery

开发者 https://www.devze.com 2023-03-06 05:04 出处:网络
Slide out is no problem i only have problem about slide in that doesnt show up and i think it didnt catch their first IF width equal 0px. sorry im really noobs about jQuery.

Slide out is no problem i only have problem about slide in that doesnt show up and i think it didnt catch their first IF width equal 0px. sorry im really noobs about jQuery.

CODE:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#ShowHideComment").click(function(){
        if ($(".iframe_comment").width() == "0px"){
            $(".iframe_comment").animate({width: "800px"}, {queue:false, duration:1000});
        }
        else{
            $(".iframe_comment").animate({width: "0px"}, {queue:false, duration:1000
           });
        }
  开发者_C百科  });
});
</script>


From the docs:

All animated properties should be animated to a single numeric value

You're not dealing with CSS property values here, but with plain integers.

$(document).ready(function(){
    $("#ShowHideComment").click(function(){
        var $comment = $(".iframe_comment");
        if ($comment.width() == 0){
            $comment.animate({width: 800}, {queue:false, duration:1000});
        }
        else{
            $comment.animate({width: 0}, {queue:false, duration:1000});
        }
    });
});

Also see width():

The difference between .css(width) and .width() is that the latter returns a unit-less pixel value


.width() returns numeric value. This line if ($(".iframe_comment").width() == "0px") should be if ($(".iframe_comment").width() == 0)

0

精彩评论

暂无评论...
验证码 换一张
取 消