Home > Web Front-end > JS Tutorial > [Couplet Advertisement] JS script class_javascript skills

[Couplet Advertisement] JS script class_javascript skills

WBOY
Release: 2016-05-16 19:26:54
Original
930 people have browsed it

//************************************************ ****************************************
//& Author: Wow Fish
//& Date: December 31, 2004
//& Website: http://www.13smile.com/
//& Blog: http://blog.csdn.net/ bpfish
//& Name: [Couplet Advertisement] JS Script Class
//& Function: Display the couplet advertisement on the page
//& Method:
//& SmileAdver.setLeftPos(10); //Set the position of the left couplet from the left side of the page (PX)
//& SmileAdver.setLeftTop(150); //Set the position of the left couplet from the top of the page (PX)
//& SmileAdver.setRightPos (10); // Set the position on the right side of the right side of the right side (PX)
// & Smileadver.setRighttop (150); // Set the position of the right pair of pairing distance (px)
// & SmileAdver.addLeftImage(link, image address, link target, image tip); //Add the image of the left couplet ad
//& SmileAdver.addRightImage(link, image address, link target, image tip); //Add The picture of the couplet advertisement on the right
//& SmileAdver.scroll();                                                                                                                                                                                                    . *************************************************** *********************
function SmileAdver_Class(){
var leftImageArray = new Array(); //Save the left advertising image array
var rightImageArray = new Array(); //Save the right ad image array
var leftPos,rightPos; )
var leftTop,rightTop; //leftTop = The position of the left ad from the top sidebar (px) rightTop = The position of the right ad from the top sidebar (px)
var lastScrollY=0;
leftPos = rightPos = 10;               //The default is 10
leftTop = rightTop = 150; /If it is not a number, the default is 10
leftPos = value;
}
this.setRightPos = function(value){
if(isNaN(value)){value = 10;} //Non-number The default is 10
rightPos = value;
}
this.setLeftTop = function(value){
if(isNaN(value)){value = 150;} //The default is for non-numbers 150
leftTop = value;
}
this.setRightTop = function(value){
if(isNaN(value)){value = 150;} //Non-number, the default is 150
rightTop = value;
}
//Add the image advertisement on the left addLeftImage (link, image address, link target, image prompt)
this.addLeftImage = function(href, image, target, title){
var imageArray = getImageArray(href,image,target,title);
if(imageArray != null){
leftImageArray[leftImageArray.length] = imageArray;
}
}
//Add the image advertisement on the right addRightImage (link, image address, link target, image prompt)
this.addRightImage = function(href,image,target,title){
var imageArray = getImageArray(href,image ,target,title);
if(imageArray != null){
rightImageArray[rightImageArray.length] = imageArray;
}
}
//Add advertising images internally, if not Image address, returns a null value, otherwise returns an array
function getImageArray(href,image,target,title){
if(image == undefined){return null;} Add
if(target == undefined || target == ""){target == "_blank"}; //The default is _blank opening method
target =" target="" target """;
if(title == undefined){ //Advertising image title prompt
title = "";
}else{
title = "title="" title """;
}
//If the link starts with www., it will automatically add http:// (otherwise, the link will be wrong)
if(href.toLowerCase().substring(0,4) == "www."){
href = "http://"; href;
}
if(image. toLowerCase().substring(0,4) == "www."){
image = "http://"; image;
}
return new Array(href,image,target,title ; Variable)
function showImageDiv(div,pos,posPX,topPx,imageArray){
var j;
document.write("
");
for(j=0; j document.write("
"); [Couplet Advertisement] JS script class_javascript skills if(j != imageArray.length-1){document.write(" ");}
}

document.write("
");
} //Scrolling advertising couplet image
this.scroll = function(){
showImageDiv ("smilediv1","left",leftPos,leftTop,leftImageArray);
showImageDiv("smilediv2","right",rightPos,rightTop,rightImageArray);
window.setInterval(scrollImage,1);
}
//Internally used to scroll advertising images
function scrollImage(){
var diffY,percent;
diffY=document.body.scrollTop;
percent=.1*( diffY-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.all.smilediv1.style.pixelTop =percent ;
document.all.smilediv2.style.pixelTop =percent;
lastScrollY=lastScrollY percent;
}
}
/////////////// //////////////////////////////End of class///////////////////// //////////////////////////////////////////////
/// //////Class usage sample code////////////////////////////////////////// /////////
var SmileAdver = new SmileAdver_Class();
SmileAdver.setLeftPos(10);
SmileAdver.setRightPos(10);
SmileAdver.setLeftTop(150);
SmileAdver.setRightTop(150);
SmileAdver.addLeftImage("http://www.138tips.com/","http://www.88ball.com/images/138tips.gif";," ","asdfasdf");
SmileAdver.addLeftImage("http://www.138tips.com/","http://www.88ball.com/images/138tips.gif");
SmileAdver .addLeftImage("http://www.138tips.com/","http://www.88ball.com/images/138tips.gif");
SmileAdver.addRightImage("http://www.138tips .com/","http://www.88ball.com/images/138tips.gif");
SmileAdver.addRightImage("http://www.138tips.com/","http://www .88ball.com/images/138tips.gif");
SmileAdver.addRightImage("http://www.138tips.com/","http://www.88ball.com/images/138tips.gif" );
SmileAdver.scroll();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template