使用translateY()进行无限滚动

时间:2014-09-19 01:50:59

标签: javascript css css3

我在绝对位置 translateY()

有3个div requestAnimationFrame上我通过相对于鼠标位置的 translateY() css声明 移动它们 但是对于我的生活,我无法弄清楚如何在传递视口后循环div

我在 requestAnimationFrame

中有以下代码
street.each(function(i,el){ // an array of the divs
        var bounds = el.getBoundingClientRect(); // get the bounds
         // here is where it gets tricky. i'm trying to detect when the div's view port has passed
        // the screen so as to start it over
        var yPos = bounds.top >= h? -y - bounds.height * 2 : (y - bounds.height * i); // y is the position of the mouse from 0,0
        $(el).css($.fx.cssPrefix + 'transform','translateY(' + yPos +'px)');    // set the translation of Y
        //console.log('street',i,'y', y, 'top: ', bounds.top, 'bottom',bounds.bottom,);
    });

0 个答案:

没有答案