2015-10-18 87 views
0

您好我想知道如何刪除傳遞的內容時向下滾動,然後添加內容回到底部。jQuery刪除內容,當它通過然後附加在末尾

示例這裏第一個無序列表已通過,它將刪除並返回底部。

請讓我知道如何在jQuery中做到這一點,因爲我找不到任何類似的插件。有無限的滾動插件,但它不會刪除傳遞的內容。

TIA

html,body{margin:0; padding:0} 
li{list-style:none; margin:0; padding:0;} 
.content { 
    background: #333; 
    color: white; 
    height: 250px; 
    } 
<ul class="unordered"> 

    <li class="header" style="z-index: 1000;"> 
     <h3>Header1</h3> 
    </li> 

    <li class="header2" style="background:#666;z-index: 1000;height: 50px;"> 
     <h5 style="margin: 0;">Header2</h5> 
    </li> 


    <li class="content"> 
    Contents 
    </li> 

</ul> 


<ul class="unordered"> 

    <li class="header" style="z-index: 1000;"> 
     <h3>Header1</h3> 
    </li> 

    <li class="header2" style="background:#666;z-index: 1000;height: 50px;"> 
     <h5 style="margin: 0;">Header2</h5> 
    </li> 


    <li class="content"> 
    Contents 
    </li> 

</ul> 
+0

你爲什麼要刪除它們?你的這種行爲意圖是什麼? – Dennis98

回答

0

好吧,雖然我不知道你爲什麼需要這一點,但這裏的代碼:

$(window).scroll(function() { 
    var scrollPos = $(window).scrollTop(); 
    var firstElem = $('body > :first-child'); 
    var firstElemHeight = firstElem.outerHeight(); 
    if (scrollPos > firstElem.offset().top + firstElemHeight) { 
     firstElem.insertAfter('body > :last-child'); 
     $(window).scrollTop(scrollPos - firstElemHeight); 
    } 
}); 

現場演示:http://jsfiddle.net/pq5wLboy/1/

+0

是的,解釋它很複雜,但這實際上是我正在尋找的。非常感謝! – user1441816

相關問題