滑出没问题我唯一的问题是滑入没有出现,我认为它没有捕捉到他们的第一个 IF 宽度等于 0px。抱歉,我对 jQuery 真的一窍不通。
代码:
<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>
最佳答案
来自 the docs :
All animated properties should be animated to a single numeric value
您在这里处理的不是 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});
}
});
});
还有 see width()
:
The difference between
.css(width)
and.width()
is that the latter returns a unit-less pixel value
关于javascript - 问题滑入/滑出 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6007490/