简体   繁体   English

问题滑入/滑出jQuery

[英]Problem Slide-In/Out 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. 滑出是没有问题的,我只有滑入的问题没有出现,我认为它没有抓住他们的第一个IF宽度等于0px的问题。 sorry im really noobs about jQuery. 对不起,我真的对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
           });
        }
    });
});
</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. 您不在这里处理CSS属性值,而是在使用纯整数。

$(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() : 请参见width()

The difference between .css(width) and .width() is that the latter returns a unit-less pixel value .css(width).width()之间的区别在于,后者返回无单位像素值

.width() returns numeric value. .width()返回数值。 This line if ($(".iframe_comment").width() == "0px") should be if ($(".iframe_comment").width() == 0) 这行if ($(".iframe_comment").width() == "0px")应该是if ($(".iframe_comment").width() == 0)

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

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