我用這個代碼來獲取元素淡入滾動時:如何檢測,如果視圖在頂部位置
<script language="JavaScript">
$(document).ready(function() {
$(window).scroll(function() {
$('#floatingDIV4').each(function() {
var bottom_of_object = $(this).position().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
if (bottom_of_window > bottom_of_object) {
$(this).animate({'opacity':'1'}, 500);
}
});
});
});
</script>
我試圖找到使被出現在滾動的元素代碼淡出在頂部的位置,但我沒有找到任何。你有什麼想法嗎?
編輯:
這些問題的答案是非常好的,但代碼沒有工作。
性能比較X,Y的值,嘗試'debounce'&'緩存elements'。 – rab