


A simple way to implement floating ads on web pages using JavaScript_javascript skills
May 16, 2016 pm 05:32 PMWalking around the Internet, you will find that the Internet is not only an ocean of information, but also an ocean of advertisements. In addition to ordinary Gif Banner and Flash, floating ads are also one of the more popular forms of advertising on the Internet nowadays. When you drag the browser's scroll bar, this kind of floating advertisement on the page can move with the screen. Although this effect has considerable practical value for advertising display, for people browsing your webpage, this is something that both hinders reading and affects reading interest, so it must not be abused. However, if you use it wisely, it can be extremely useful.
It is not difficult to create the effect of a floating advertisement. If you have a basic knowledge of JS, you can write one yourself. If you are too lazy to write, download a special effects tool online and paste the code as prompted. . However, if you want to really understand how it is made, you need to master some JS knowledge. Here I will introduce to you a simple floating advertisement method.
The following code can be placed between <body></body>, during which I added some comments (i.e. the text after "//" and "<!—" "-->" text between).
<SCRIPT FOR=window EVENT=onload LANGUAGE=" JScript">
initAd();//After loading the page, call the function initAd()
</SCRIPT>
<script language="JScript">
<! --
function initAd() {
document.all.AdLayer.style.posTop = -200;//Set the ad layer relative to the fixed y-direction position after the onLoad event is fired
document.all .AdLayer.style.visibility = visible//Set the layer to be visible
MoveLayer(AdLayer);//Call function MoveLayer()
}
function MoveLayer(layerName) {
var x = 600; //The floating ad layer is fixed at the x-direction position of the browser
var y = 300;//The floating ad layer is fixed at the y-direction position of the browser
var diff = (document.body.scrollTop y - document. all.AdLayer.style.posTop)*.40;
var y = document.body.scrollTop y - diff;
eval("document.all." layerName ".style.posTop = y");
eval("document.all." layerName ".style.posLeft = x");//Mobile advertising layer
setTimeout("MoveLayer(AdLayer);", 20);//Set 20 milliseconds before calling Function MoveLayer()
}
//-->
The AdLayer in MoveLayer() must also be modified accordingly), including a picture with a link -->
<div id=AdLayer style=position:absolute; width:61px; height:59px; z-index :20; visibility:hidden;; left: 600px; top: 300px>
<a href="http://www.jb51.net"><img src=../qqkk2000.gif border= "0" height="60" width="60"></a>
</div>
Remember, use floating ads with caution. When considering the use of special effects, you must also take the viewer’s feelings into consideration and do not abuse them!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to send web pages to desktop as shortcut in Edge browser?

How to turn off the ads recommended by 360 Browser? How to turn off ads recommended by 360 Browser on PC?

Possible reasons why the network connection is normal but the browser cannot access the web page

How to set up web page automatic refresh

How to completely turn off ads in Moments

What to do if the webpage cannot be opened

What should I do if the images on the webpage cannot be loaded? 6 solutions

How to turn off ads in the new version of Edge? How to block Edge personalized ads
