for(x = 0; x < 3; x++)
{
var board = document.createElement('div');
board.className = "div";
document.getElementById('body').insertBefore(board, document.getElementById("body").firstElementChild);
}
window.onscroll = function()
{
'use strict';
if(body.scrollTop >= body.children[0].offsetTop)
{
body.children[0].style.opacity = ".1"
};
if(body.scrollTop >= body.children[1].offsetTop - 100)
{
body.children[1].style.opacity = ".1"
}
};
如果ScrollTop
等于div元素的Body
,我期待offsetTop
的样式。我正在尝试缩短此代码,因为我需要20个。