我正在制作一个演示。它不会预置第一个 div 数据 div 第二个 div 数据(当用户滚动到顶部时。它不会预置数据)。
您能解释一下为什么它没有发生吗?
$("#fullContainer").scroll(function(){
if($(this).scrollTop() === 0){
alert("----")
$("#firstcontainter").html(secondData);
$("#secondcontainter").prependTo("#firstcontainter");
}
});
最佳答案
因为#secondcontainer
是#firstcontainer
的 child ,当你打电话时...
$("#firstcontainter").html(secondData);
您正在完全删除 #secondcontainer
。试试这个...
var second = $('#secondcontainer').detach();
$("#firstcontainer").html(secondData).prepend(second);
您还有一个未关闭的 <div>
以及其他一些错别字。全部固定在这里 - http://jsfiddle.net/G6jJS/9/
关于javascript - 为什么前置功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22163014/