我非常了解jQuery但是使用纯JavaScript我有问题。
你能帮我转换jquery代码到javascript吗?谢谢:))
这是我的代码。
var container = $('.container');
$(window).scroll(function(event) {
var scrollTop = $(window).scrollTop();
var containerTop = container.position().top;
var containerHeight = container.outerHeight();
var blockHeight = $('.game-block').height();
var callPosition = (containerTop + containerHeight) - blockHeight;
if(scrollTop >= callPosition) {
//do ajax call
}
});
答案 0 :(得分:-1)
var container = document.getElementByClassName('container');
window.addEventListener('scroll', function() {
var scrollTop = window.scrollY;
var containerTop = container.offsetTop;
var containerHeight = container.offsetHeight;
var blockHeight = document.getElementByClassName('game-block').clientHeight;
var callPosition = (containerTop + containerHeight) - blockHeight;
});