JavaScript floating ad code, Pure div/css floating ad code, compatibility very good JS right corner with floating ad code

Source: Internet
Author: User
Tags setinterval visibility

Random floating image ads based on JavaScript code, JavaScript image ads

There are many such codes on the internet, but not necessarily in line with the standard, because in the head plus <! DOCTYPE html> similar tags, the floating effect will expire, the following share a standard floating code, so that the needs of friends to avoid a lot of code to change the Cumbersome.

Code one:

The code is as Follows:

<! DOCTYPE Html>

The above code implements our requirements, Red div blocks can be floating randomly in the web page, and compatible with each browser. The implementation process of the code is not introduced here, if there are any questions can be posted Message.

Code two: JS Random floating AD Code specific examples

The code is as Follows:

<!--random Floating ads start--><div id= "float" style= "position:absolute; z-index:3, (i suggest you set this to 100 so that the floating chart will not be Obscured) left:512px; width:83px; top:9px; height:53px; " >  </div><script type= "text/javascript" > <!--   Random floating ads--var xpos=0,ypos=0;//x,y axis coordinates var xon=0;//picture in the X axis move direction var yon=0;//picture in the Y axis moving direction var step=1; Move distance var img=document.getelementbyidx_x ("float");//picture layer function FLOATP () {var width=document.body.clientwidth;//browse Device width var height=document.body.clientheight;//browser height var hoffset=img.offsetheight;//picture height var woffset=img.offsetwidth;// Picture width img.style.left=xpos+document.body.scrollleft;//picture Distance to the left of the browser img.style.top=ypos+document.body.scrolltop;//   Image distance from the top of the browser if (yon==0) {ypos=ypos+step;//picture moves up and down in the y-axis}else{ypos=ypos-step;   } if (ypos<0) {//float to the top and move downward along the y-axis yon=0;   ypos=0;   If (ypos>= (height-hoffset)) {//float to the low end and move upward along the y-axis yon=1;   ypos= (height-hoffset); } If (xon==0) {//x axis moves to the right xpos=xpos+step;  }else{xpos=xpos-step;//x axis Move left} if (xpos<0) {//float to the left to move xon=0 to the right along the x-axis;   xpos=0;   If (xpos>= (width-woffset)) {//float to the right, move Xon=1 to the left along the x-axis;   xpos= (width-woffset);  } setTimeout ("FLOATP ()", 30);//timed Call. } WINDOW.ONLOAD=FLOATP ();</script>

  code as Follows:

<script>var x = 50,y = 60//the initial position of the floating layer, respectively, the initial x-coordinate of the corresponding layer and the y-coordinate var xin = true, Yin = true//the x-coordinate and y-coordinate of the judgment layer are within the control range, Xin is the true layer to the right, no Then to the left; the yin is really a layer down, otherwise up var step = 1//layer Moves the step, the higher the value moves faster var delay = 10//layer Move Time interval, in milliseconds, the smaller the value moves faster var obj= document.getelementbyidx_x ("float")//capture ID for AD layer as floating target function Floatad () {var l=t=0//layer move range left boundary (L) and Upper boundary (T) coordinate var r= Document.body.clientwidth-obj.offsetwidth//layer move right boundary var B = document.body.clientheight-obj.offsetheight// The bottom boundary of the layer movement Obj.style.left = x + document.body.scrollLeft//update layer x-coordinate for motion in x-axis direction Document.body.scrollLeft the distance to the right of the scrollbar of the document area to ensure that the layer is still within the visible range Obj.style.top = y + document.body.scrollTop//update layer y-coordinates when the scrollbar is Right-pulled. To achieve motion in the y-axis direction; document.body.scrollTop the distance to the scroll bar of the document area to ensure that the layer is still visible within the visibility range when the scrollbar is pulled down x = x + step* (xin?1:-1)// Determine the direction of motion of the layer on the x-axis by judging the range of the layer if (x < L) {xin = true; x = L}//layer exceeds the left boundary when processing if (x > R) {xin = false; x = R}//layer exceeds right boundary when processing y = y +  step* (yin?1:-1)//determines The motion direction of the layer on the y-axis by judging the range of the layer if (y < T) {yin = true; y = T}//layer exceeds the upper boundary when processing if (y > B) {yin = false; y = b} The processing of the layer beyond the lower Boundary}var itl= setinterval ("Floatad () ", delay)//per delay seconds Floatad function obj.onmouseover=function () {clearinterval (itl)}//layer clears the above interval event when the mouse is Moved. The implementation layer stops moving when the mouse moves on the effect obj.onmouseout=function () {itl=setinterval ("floatad ()", Delay)}//layer begins the interval event when the mouse is moved, The effect of the implementation layer on the movement of the mouse when moving away </script>

Help the home friendship reminds you need to note:

Insert flash and floating ads on your web page, and you'll find out how we can solve this problem when floating ads float to Flash.

Add the following statement to the location of the flash code

<param name= "wmode" value= "opaque" >

Cases:

If the following is the code where flash is located:

The code is as Follows:

<object classid= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase= "http://download.macromedia.com/pub/ shockwave/cabs/flash/swflash.cab#version=6,0,29,0 "width=" 780 "height=" 165 "><param name=" movie "value=" banner1.swf "><param name=" quality "value=" high "><param name=" menu "value=" false "><param name=" Wmode "value=" opaque "><!--mainly this sentence--><embed src=" banner1.swf "quality=" High "pluginspage="/http Www.macromedia.com/go/getflashplayer "type=" Application/x-shockwave-flash "width=" 780 "height=" 165 "></embed ></object>

This example for everyone to share JavaScript to achieve Full-screen floating ads for your reference, the specific content as follows

Main Use method

Web page visible Area width: document.body.clientWidth;
Web page visible Area high: document.body.clientHeight;

Web page visible Area width: document.body.offsetWidth (including the width of the edge);
Web page visible Area high: document.body.offsetHeight (including the width of the edge);

SetInterval

The function of the SetInterval action is to call functions, methods, or objects at intervals of time when the animation is Played. You can use this action to update a variable or update time display from a database.

The syntax format for the setinterval action is as Follows:

SetInterval (function,interval[,arg1,arg2,...... argn])   setinterval (object,methodname,interval[,arg1,arg2, .... argn])

The first format is the default syntax for the SetInterval function in the standard actions panel, and the second format is the method used in the expert mode Action.
The parameter function is a function name or a reference to an anonymous Function.
The object parameter specifies the objects derived from the object Objects. MethodName the method to invoke in the object parameter.
Interval the time between a function or a MethodName call two times, in MILLISECONDS. The following arg1 are optional parameters for setting parameters passed to function or Methodname.
SetInterval It sets a time interval that is less than the animation frame rate (10 frames per second, which is equivalent to 100 milliseconds), the function is called as close to interval as Possible. You must also use the Updateafterevent action to ensure that the screen is refreshed with sufficient frequency. If the interval is greater than the animation frame rate, It is only called when the playhead enters a frame each time to reduce the effect of each refresh of the Screen.

Clearinterval

The function of Clearinterval action is to clear the call to the SetInterval function

Its syntax format is as Follows:
Clearinterval (intervalid); Intervalid is the object returned after the SetInterval function is Called.

Ad Move Effect instance

    </script>  </body>

The above is the whole content of this article, I hope that everyone's study has Helped.

The year Wang Xiaoyuan Handsome total embarrassing pill days bless rogue three gold Picasso Wang Mian Wind small zheng lee brother God bless Shenman information

JavaScript floating ad code, Pure div/css floating ad code, compatibility very good JS right corner with floating ad code

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.