Tangram framework response-based image Loading Method

Source: Internet
Author: User

Various websites often see pages scroll to the visible area before loading the corresponding image resources. What is his nature? This article analyzes whether the current element is in a visible area.

Suppose: h1 = the height of the scroll bar rolling
W1 = scroll width
H2 = screen height
Obj indicates the current object {x: the position of the current object relative to the upper left corner of the document x, y: The current object relative to the y in the upper left corner of the document}

This is the case.
In the Y axis direction: if (obj. x> h1 & obj. x

Similarly, in the X axis direction, and so on.

If you use the tangram framework, you can write as follows:

Copy codeThe Code is as follows:
Baidu. more = baidu. more | | {};

Baidu. more. scrollLoading = (function (){

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 <top + viewHeight) |

(Pos. top + obj. offsetHeight> top & pos. top + obj. offsetHeight <top + viewHeight) |

(Pos. left> left & pos. left <left + viewWidth) |

(Pos. left + obj. offsetWidth> left & pos. left + obj. offsetWidth <left + viewWidth )){

Loading ();

};

Return {

ScrollLoad: scrollLoad

}

})()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.