我有一個容器充滿了內容。我試圖點擊一個按鈕,並推動所有的內容向下,說700px。一旦內容被推下,一個新的頁面加載到現在顯示的空間中,因爲內容被壓下。我也想要推動相同的按鈕來反向播放動畫,在卸載新加載的內容時推送內容。點擊容器內容下載,將內容加載到空間顯示Jquery
我會如何做到這一點與jQuery?
我有一個容器充滿了內容。我試圖點擊一個按鈕,並推動所有的內容向下,說700px。一旦內容被推下,一個新的頁面加載到現在顯示的空間中,因爲內容被壓下。我也想要推動相同的按鈕來反向播放動畫,在卸載新加載的內容時推送內容。點擊容器內容下載,將內容加載到空間顯示Jquery
我會如何做到這一點與jQuery?
看的jQuery效果和操控API
http://api.jquery.com/category/effects/
http://api.jquery.com/category/manipulation/
這些步驟應該足夠
<button id="showHideTopContent">Show Hide Content</button>
<div id="container">
<div id="topContent" style="display:none;">
This is top content
<hr />
</div>
<div id="topContent" style="display:none;">
This is bottom content.
</div>
</div>
<script type="text/javascript">
$(function() {
$("#showHideTopContent").click(toggleTopContent);
});
function toggleTopContent() {
var topContent = $("#topContent");
var bottomContent = $("#bottomContent");
if(!topContent.is(":hidden")) {
topContent.hide();
bottomContent.slideUp("slow");
} else {
// if you want the content to come from AJAX or so do it here
// ....
// If you do so, the topContent div should remain there, but empty.
$("#topContent").slideDown("slow");
}
}
</script>