JavaScript AD Floating Effect code

Source: Internet
Author: User
JavaScript ad floating effect code

This example is mainly a Web page floating advertising code, is a small box floating in the Web page. The implementation of this web page floating ads is also very simple, in the Web page through JavaScript to find ID img1 Div, and then through the JS code to achieve the Web page floating ads.
Very simple a div and then call Js.js to control this div

Look at the Js.js code in the floating ad code of the Web.

<script type= "Text/javascript" >

var x=0;

var y=0;

var vx=1;

var vy=1;//

function Move () {

var Pic=document.getelementbyid ("Pic") each time it moves;

X=X+VX;

Y=y+vy;

pic.style.left=x+ "px";

pic.style.top=y+ "px";

If the x+ picture is wider than the width of the window or x<0, the reverse moves if 

(x+pic.offsetwidth) >document.body.clientwidth| | x<0) {

VX=-VX};

if ((y+pic.offsetheight) >document.body.clientheight| | y<0) {

vy=-vy};

}

SetInterval ("Move ()");

function shut () {

document.body.removeChild (document.getElementById ("pic"))

}

</script>

See the code in HTML

<body style= "padding:0px;margin:0px;" >

<div id= "pic" style= "Position:absolute" > <input

"button" value = "Close" style= "Position:absolute" onclick= "Shut ()" >

</div>

</body>

The novice asked the great God more guidance

Deephug

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.