Code example of js left-right suspension couplet advertisement, js Couplet

Source: Internet
Author: User

Code example of js left-right suspension couplet advertisement, js Couplet

A section of js left and right floating ad code. You only need to modify the ad image address and connection address, and the corresponding parameters can be adjusted based on the page to use this section of left and right floating ad code.

Code:

Var delta = 0.15 var collection; function floaters () {this. items =; this. addItem = function (id, x, y, content) {document. write ('<DIV id =' + id + 'style = "Z-INDEX: 10; POSITION: absolute; width: 80px; height: 60px; left:' + (typeof (x) = 'string '? Eval (x): x) + '; top:' + (typeof (y) = 'string '? Eval (y): y) + '">' + content + '</DIV>'); var newItem ={}; newItem. object = document. getElementById (id); newItem. x = x; newItem. y = y; this. items [this. items. length] = newItem;} this. play = function () {collection = this. items setInterval ('play () ', 10) ;}} function play () {for (var I = 0; I <collection. length; I ++) {var followObj = collection [I]. object; var followObj_x = (typeof (collection [I]. x) = 'string '? Eval (collection [I]. x): collection [I]. x); var followObj_y = (typeof (collection [I]. y) = 'string '? Eval (collection [I]. y): collection [I]. y); if (followObj. offsetLeft! = (Document. body. scrollLeft + followObj_x) {var dx = (document. body. scrollLeft + followObj_x-followObj.offsetLeft) * delta; dx = (dx> 0? 1:-1) * Math. ceil (Math. abs (dx); followObj. style. left = followObj. offsetLeft + dx;} if (followObj. offsetTop! = (Document. body. scrollTop + followObj_y) {var dy = (document. body. scrollTop + followObj_y-followObj.offsetTop) * delta; dy = (dy> 0? 1:-1) * Math. ceil (Math. abs (dy); followObj. style. top = followObj. offsetTop + dy;} followObj. style. display = '';} var theFloaters = new floaters (); theFloaters. addItem ('followdiv1 ', 'document. body. clientWidth-112 ', 230,' <a href = left link address target = _ blank>  </a> '); theFloaters. addItem ('followdiv2', 12,230, '<a href = right link address target = _ blank>  </a> '); theFloaters. play ();

Save it as a *. js file and reference it on the page: <script src = "*. js"> </script>. * indicates the file name you saved!
Note: Modify the ad image address and connection address! The corresponding parameters can be adjusted according to the page.

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.