Javascript implements simple examples of fixed ad effects on both sides _ javascript skills

Source: Internet
Author: User
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" ;}} scriptAd

Advertisement on the left

Advertisement on the right

I hope this article will help you design javascript programs.

Related Article

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.