This article mainly introduces how to implement a simple fixed advertisement effect between the left and right sides of javascript. The example shows how to implement a fixed advertisement in javascript, which is of great practical value, if you need it, refer to the example in this article to describe how to implement a simple fixed advertisement effect between the left and right sides of js. Share it with you for your reference. The specific analysis is as follows:
Most websites have fixed advertising spaces on both sides. below is the simplest code to achieve this effect. It may be a little jitters when I scroll under ie. This problem will be solved later, first.
Key Aspect 1:
var adtop = adleft.offsetTop;
Obtain the position of the element above the distance, which must be used for scrolling.
Key Aspect 2:
The Code is as follows:
Adleft.style.top=adtop((document.doc umentElement. scrollTop | document. body. scrollTop) + "px ";
When scrolling, assign a value to the above position of the element to the distance between the element itself and the above plus the scroll distance.
Code:
Untitled documentScript window. onload = function () {var adleft = document. getElementById ("adleft"); var adright = document. getElementById ("adright"); var adtop = adleft. offsetTop; window. onscroll = function () {adleft. style. top = adtop + (document.doc umentElement. scrollTop | document. body. scrollTop) + "px"; adright. style. top = adtop + (document.doc umentElement. scrollTop | document. body. scrollTop) + "px" ;}} scriptAdAdvertisement on the left
Advertisement on the right
I hope this article will help you design javascript programs.