0
我使用以下代碼來顯示滾動到視圖中的div。我想簡化這一點,並顯示頁面加載時,而不是滾動到視圖時。任何幫助都會很棒。非常感謝。使用Javascript縮放頁面加載div
var animateHTML = function() {
var elems,
windowHeight
var init = function() {
elems = document.getElementsByClassName('hidden')
windowHeight = window.innerHeight
_addEventHandlers()
}
var _addEventHandlers = function() {
window.addEventListener('scroll', _checkPosition)
window.addEventListener('resize', init)
}
var _checkPosition = function() {
for (var i = 0; i < elems.length; i++) {
var posFromTop = elems[i].getBoundingClientRect().top
if (posFromTop - windowHeight <= 0) {
elems[i].className = elems[i].className.replace('hidden', 'fade-in-element')
}
}
}
return {
init: init
}
}
animateHTML().init()