JS implementation Floating box follow the page scroll, and finally stay in the original position

Source: Internet
Author: User

The left-hand suspended QR code will follow the page up or down and end up in its original position.

<Divstyle= "background:red; width:1000px; height:7000px; margin:auto;">&nbsp;&nbsp;</Div><DivID= "AA"style= "position:absolute;right:0px; top:4600px;"><imgsrc= "001.jpg"/></Div><Script>functionScrollx (p) {varD=DOCUMENT,DD=d.documentelement,db=d.body,w=Window,o=d.getElementById (p.id), IE6= /MSIE 6/i.test (navigator.useragent), Style,timer; if(o) {o.style.csstext+=";p osition:"+(P.F&&!IE6?'fixed':'Absolute')+";"+(P.L==undefined?'left:0;':'Left :'+P.L+'px;')+(p.t!=undefined?'Top:'+p.t+'px':'bottom:0'); if(P.F&&IE6) {O.style.csstext+='; Left:expression (Documentelement.scrollleft +'+(P.L==undefined?Dd.clientwidth-O.OFFSETWIDTH:P.L)+'+ "px"); Top:expression (Documentelement.scrolltop +'+(p.t==undefined?Dd.clientheight-o.offsetheight:p.t)+'+ "px");'; Dd.style.cssText+='; Background-image:url (About:blank); background-attachment:fixed;'; }Else{    if(!p.f) {W.onresize=W.onscroll= function() {clearinterval (timer); Timer=SetInterval (function(){        //dual choice to fix chrome under XHTML parsing when Dd.scrolltop is 0        varSt=(Dd.scrolltop||db.scrolltop), C; C=St-O.offsettop+(p.t!=undefined?p.t: (W.innerheight||dd.clientheight)-o.offsetheight); if(c!=0) {O.style.top=O.offsettop+Math.ceil (Math.Abs (c)/* (c<0?-1:1) + ' px ';        }Else{clearinterval (timer); }       },Ten}}}}} Scrollx ({ID:'AA', T: -,    }) /*ID you want to scroll the contents of the ID l the position of the horizontal axis is not written as close to the right t you want to put on the page of the location by default is affixed to the bottom 0 is affixed to the top side F 1 means fixed not write or 0 means scrolling*/</Script>

JS implementation Floating box follow the page scroll, and finally stay in the original position

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.