Home >Web Front-end >JS Tutorial >Tangram framework responsive loading image method_javascript skills
Various websites often see pages scrolling to the visible area and then loading the corresponding image resources. What is its essence? The analysis in this article is very simple, which is to determine whether the current element is within the visible area
Assumption: h1 = the height of the scroll bar rolled away
w1 = the width of the scroll bar rolled away
h2 = height of the screen
obj represents the current object {x: the current object relative to the upper left corner of the document Position x,y: y}
should be judged like this: if(obj.x>h1&&obj.x
var top = baidu.page.getScrollTop(),
left = baidu.page.getScrollLeft(),
viewHeight = baidu.page.viewHeight(),
viewWidth = baidu.page.viewWidth();
var scrollLoad = function(element){
var obj = baidu.g(element)||{};
var pos = baidu.dom.getPosition(element);
if((pos.top>top&&pos.top
loading();
};
return {
scrollLoad :scrollLoad
}
})()