如何缩短功能滚动代码?

时间:2017-04-09 12:44:15

标签: javascript

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个。

0 个答案:

没有答案