JS code fragment: Determine whether an element enters the viewable area

Source: Internet
Author: User
Determine if an element was in the visible viewportfunction Isinviewport (Element) {  var rect = ELEMENT.GETBOUNDINGCL Ientrect ();  var html = document.documentelement;//in IE, the default coordinates are calculated from (2,2), resulting in a final distance of two pixels more than the other browsers, we need to do a compatibility.    var top = document.documentElement.clientTop;//non IE is 0,ie for 2    var left= document.documentElement.clientLeft;  Return (    rect.top-top >= 0 &&    rect.left-left >= 0 &&    rect.bottom-top <= (window.in Nerheight | | Html.clientheight) &&    rect.right-left <= (window.innerwidth | | html.clientwidth)  );}

JS code fragment: Determine whether an element enters the viewable area

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.