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.