Advertising Elastic Ball Effect

Source: Internet
Author: User

Directly on the code

CSS just needs to give the moving element to position it on the line

1 <style type= "Text/css" > 2     #imgId{3        position:absolute;  4        left:0px;  5        top:0px;  6     }7</style>

JS Code

1<script type= "Text/javascript" >2 3     varLeftinc;4     varTopinc;5     varCurrleft;//the current left of the picture;6     varCurrtop;//the current top of the picture;7     varwidth;8     varheight;9     varclientwidth;Ten     varclientheight; One     varscrollleft; A     varscrolltop; -  -     functioninit () { theLeftinc = 1; -Topinc = 1; -Currleft = 0;//the current left of the picture; -currtop = 0;//the current top of the picture; +width = 200; -Height = 200; +Clientwidth=document.documentelement.clientwidth | |Document.body.clientWidth; AClientheight=document.documentelement.clientheight | |Document.body.clientHeight; atScrollleft=document.documentelement.scrollleft | |Document.body.scrollLeft; -Scrolltop=document.documentelement.scrolltop | |Document.body.scrollTop; -          -     } -  -     functionChangescroll () { inScrollleft=document.documentelement.scrollleft | |Document.body.scrollLeft; -Scrolltop=document.documentelement.scrolltop | |Document.body.scrollTop; to     } +  -     functionStartmove () { theSetInterval ("Gostep ()", 10); *     } $ Panax Notoginseng     functionGostep () { -Scrollleft=document.documentelement.scrollleft | |Document.body.scrollLeft; theScrolltop=document.documentelement.scrolltop | |Document.body.scrollTop; +          A         //2. Change the value of the left and top of the image label object; theCurrleft = currleft+Leftinc; +Currtop = currtop+Topinc; -          $         //if the left coordinate of the picture is greater than (the page visual width-the width of the picture) $         if(currleft>=clientwidth-width+scrollleft) { -Leftinc=-1; -}Else if(Currleft<=scrollleft) {//the left of the picture is less than or equal to 0; theLeftinc = 1; -         }Wuyi          the         if(currtop>=clientheight-height+scrolltop) { -Topinc=-1; Wu}Else if(currtop<=scrolltop) { -Topinc = 1; About         } $          -         //1. Get the image Tag object -         varimg = document.getElementById ("Imgid"); -Window.status = currleft+ "," +Currtop; AImg.style.left = currleft+ "px"; +Img.style.top = currtop+ "px"; the     } -  $</script>

Page

1 <Bodyonload= "init (); Startmove ()"onscroll= "Changescroll ()"onresize= "Changescroll ()">2     <imgID= "Imgid"src= "Fr.png"style= "width:150px;3 height:200px; " />    4     5 </Body>

This will allow you to run directly

Advertising Elastic Ball Effect

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.