How to load images in a responsive manner using the tangram framework _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how to use the tangram framework to load images in a responsive manner. You can refer to using various websites to often see the page rolling 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. xh1 & | obj. x + obj. offsetHeight, similarly, in the x axis direction, and so on

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

The 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

(Pos. top + obj. offsetHeight> top & amp; pos. top + obj. offsetHeight

(Pos. left> left & amp; pos. left

(Pos. left + obj. offsetWidth> left & pos. left + obj. offsetWidth

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.