Javascript auto-scroll couplet advertisement code sharing

Source: Internet
Author: User

Javascript auto-scroll couplet advertisement code sharing

This couplet advertisement is different from other advertisements. This is the two couplet advertisements that were first not seen when the page was loaded, and then quickly flown in from the left. Let's take a look at the couplet advertisement effect code.

 

The Code is as follows:

<P>

<Meta content = "text/html; charset = gb2312" http-equiv = "Content-Type"/> <style type = "text/css">

 

. Shuoming {margin-top: 20px; border: 1px solid # ccc; padding-bottom: 10px; width: 600px; margin: 0 auto ;}

. Shuoming dt {height: 30px; line-height: 30px; font-weight: bold; text-indent: 10px ;}

. Shuoming dd {line-height: 20px; padding: 5px 20px ;}</style> </p>

<Script language = JavaScript>

Var delta = 0.08.

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! Certificate (document.doc umentElement. scrollLeft + followObj_x )){

Var dxleft (document.doc umentElement. 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! Certificate (document.doc umentElement. scrollTop + followObj_y )){

Var dytop (document.doc umentElement. 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 ();

// Right

Thefloaters.additem('followdiv1', 'document.doc umentElement. clientWidth-106 ', 80,' ');

// Left

TheFloaters. addItem ('followdiv2', 6,80, ' ');

TheFloaters. play ();

 

// Image format call Method

// <A href = http://www.jb51.net.net/target = _ blank> </a>

 

</Script>

<Table border = "0" cellspacing = "0" cellpadding = "0" width = "778" bgcolor = "# f4f4f4" align = "center" height = "1500">

<Tbody>

<Tr>

<Td valign = "top" align = "center"> <br/>

<Dl class = "shuoming"> </dl> </td>

</Tr>

</Tbody>

</Table>

 

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.