js web page side scrolling advertising effect with the page

高洛峰
Release: 2017-02-04 14:26:08
Original
1488 people have browsed it

a.ScrollTop calculation;
b. Positioning value calculation of scroll element;
c. Scroll cycle setting;
The code is as follows:
css part:

/*测试用的高度*/ body{ height:3000px;} div,ul,li,body{margin:0; padding:0;} /*position:absolute;用于元素的定位*/ #roll{width:50px; height:100px; background:#99CC00; position:absolute;}
Copy after login

Html code:

 
Copy after login

JS code:

var roll=document.getElementById('roll'), initX=0, initY, compY, sp=15, //可调整时间间隔,步进值不宜过大,不然IE下有点闪屏; timeGap=5, doc=document.documentElement, docBody=document.body; compY=initY=200; roll.style.right=initX+"px"; ;(function(){ var curScrollTop=(doc.scrollTop||docBody.scrollTop||0)-(doc.clientTop||docBody.clientTop||0); //每次comP的值都不一样;直到roll.style.top===doc.scrollTop+initY; compY+=(curScrollTop+initY-compY)/sp; roll.style.top=Math.ceil(compY)+"px"; setTimeout(arguments.callee,timeGap); })();
Copy after login

For more js web page side scrolling advertising effects, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!