【发布时间】:2013-06-29 15:10:17
【问题描述】:
我想用 jQuery .animate css position property 从 position : relative 到 position : absolute。
我在 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>
我与jQuery().animate 合作但不起作用,我与jQuery().css 合作并且有效,但不是我想要的。
这就是我所做的:
$(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);
});
});
非常感谢您的帮助!
最好的问候。
【问题讨论】:
标签: jquery jquery-animate position css-position