我想.animate css position property from position : relative
to position : absolute
with jQuery。为什么jQuery.animate位置不起作用?
我有一个div div容器内的小div,我想扩展这个div时点击一个按钮,以适应窗口。
HTML:
<div id="container"> <!-- div with position:relative -->
<div id="content"> <!-- i want to expand this div using position:absolute to extract it from the container and to give width and height 100% -->
<button id="full">Full</button>
<button id="collapse">Collapse</button>
</div>
</div>
我TREID与jQuery().animate
但不与jQuery().css
和工程工作,我TREID,但不是我想要的。
这是我做的:
$(document).ready(function() {
$("#collapse").hide();
$("#full").bind("click", function (e) {
e.preventDefault();
$("#content").animate({
width: "1000px",
height:"1000px",
top:0,
left:0
}, 500).css({"overflow": "visible", "position":"absolute"});
$("#full").hide(100);
$("#collapse").show(100); // can i use $("#collapse").css("display","block"); ?
});
$("#collapse").bind("click", function (e) {
e.preventDefault();
$("#content").animate({
width: "400px",
height: "300px",
}, 500).css({"overflow": "visible", "position":"relative"});
$("#full").show(100);
$("#collapse").hide(100);
});
});
非常感谢您的帮助!
最好的问候。
非常感谢,但我想动画的位置,因为当我点击“全按钮”div移动到顶部没有任何效果,然后开始动画。你注意到了吗? –
啊,是的,让我再次测试它是否可以制作动画。 – yeyene
检查我的更新答案,并再次演示,现在你想要的动画工作(但不是第一次),我也不知道为什么。但是在第一次点击之后,它正在制作漂亮的顶部和左侧动画。 – yeyene