jquery fluttering Advertising window

Source: Internet
Author: User

See some of the ads in the Web page move, you do the implementation of a bit. After all, programming is important.

Implementation ideas:

1, the Advertising window will open the timer, while moving toward the x-axis and y-axis direction of the window. When moving to the edge of the visible area range,

Move in the opposite direction. So the X-and Y-axes of a window ad should be judged 2 times respectively. Whether to the border. To the boundary, it changes the speed of operation,

Move in the opposite direction.

In this ad window, I used a picture to simulate. Specific as follows:

Html:

<src= "images/move.jpg"/>

Css:

  img{            display: block;             Position: absolute;             top: 0;             Left: 0;        }

Jq

$(function(){            varwindowheight=$ (window). Height (); varimgheight=$ ("img"). Height (); varWindowwidth=$ (window). width (); varimgwidth=$ ("img"). width (); varispeedy=0;/******* distance from the top of the window ********/           varvy=10;/*******y axis operating speed ********/           varispeedx=0;/******* distance from window to the left ********/           varvx=10;/*******x axis operating speed ********/           functionMove () {if(ispeedx>=windowwidth-imgwidth) {Ispeedx=windowwidth-imgwidth;/******* the distance from the left side of the window equals the viewable area minus the width of the ad window. Just to the bottom of the screen ********/VX=-10;/******* speed value is negative. Advertising window go back ********/                }               if(ispeedx<=0) {/********* distance Visible area is 0 * * * **/VX= 10;/*the ****** speed value is a positive number. The advertising window goes back ********/               }               if(ispeedy<0) {VY=10               }               if(ispeedy>=windowheight-imgheight) {Ispeedy=windowheight-ImgHeight; VY=-10} ispeedy+=VY; Ispeedx+=VX; $("IMG"). Animate ({top:ispeedy,left:ispeedx},100); }           varTimer=NULL; Timer=setinterval (function() {Move ()},100); })

jquery fluttering Advertising window

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.