[对联广告] JS脚本类
时间:2021-08-14 08:32:54|栏目:JavaScript代码|点击: 次
//****************************************************************************************
//& 作者: 哇哇鱼
//& 日期: 2004年12月31日
//& 网站: http://www.13smile.com/
//& Blog: http://blog.csdn.net/bpfish
//& 名称: [对联广告] JS脚本类
//& 作用: 显示页面的对联广告
//& 方法:
//& SmileAdver.setLeftPos(10); //设置左边对联的距页面左边的位置(PX)
//& SmileAdver.setLeftTop(150); //设置左边对联的距页面顶部的位置(PX)
//& SmileAdver.setRightPos(10); //设置右边对联的距页面右边的位置(PX)
//& SmileAdver.setRightTop(150); //设置右边对联的距页面顶部的位置(PX)
//& SmileAdver.addLeftImage(链接,图片地址,链接目标,图片提示); //添加左边对联广告的图片
//& SmileAdver.addRightImage(链接,图片地址,链接目标,图片提示); //添加右边对联广告的图片
//& SmileAdver.scroll(); //显示对联广告
//&
//****************************************************************************************
function SmileAdver_Class(){
var leftImageArray = new Array(); //保存左边的广告图片数组
var rightImageArray = new Array(); //保存右边的广告图片数组
var leftPos,rightPos; //leftPos = 左边广告的距左边栏位置(px) rightPos = 右边广告的距右边栏位置(px)
var leftTop,rightTop; //leftTop = 左边广告的距顶边栏位置(px) rightTop = 右边广告的距顶边栏位置(px)
var lastScrollY=0;
leftPos = rightPos = 10; //默认为10
leftTop = rightTop = 150; //默认为150
this.setLeftPos = function(value){
if(isNaN(value)){value = 10;} //非数字则默认为10
leftPos = value;
}
this.setRightPos = function(value){
if(isNaN(value)){value = 10;} //非数字则默认为10
rightPos = value;
}
this.setLeftTop = function(value){
if(isNaN(value)){value = 150;} //非数字则默认为150
leftTop = value;
}
this.setRightTop = function(value){
if(isNaN(value)){value = 150;} //非数字则默认为150
rightTop = value;
}
//添加左边的图片广告 addLeftImage(链接,图片地址,链接目标,图片提示)
this.addLeftImage = function(href,image,target,title){
var imageArray = getImageArray(href,image,target,title);
if(imageArray != null){
leftImageArray[leftImageArray.length] = imageArray;
}
}
//添加右边的图片广告 addRightImage(链接,图片地址,链接目标,图片提示)
this.addRightImage = function(href,image,target,title){
var imageArray = getImageArray(href,image,target,title);
if(imageArray != null){
rightImageArray[rightImageArray.length] = imageArray;
}
}
//内部添加广告图片使用,如果没有图片地址,则返回一个null值,否则返回一个数组
function getImageArray(href,image,target,title){
if(image == undefined){return null;} //没有图片地址,不添加
if(target == undefined || target == ""){target = "_blank"}; //默认为_blank打开方式
target = " target=\"" + target + "\"";
if(title == undefined){ //广告图片title提示
title = "" ;
}else{
title = " title=\"" + title + "\"";
}
//链接以www.开头则自动加上http:// (否则链接时会链接错误)
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);
}
//内部显示图片横幅所用 showImageDiv(div的名称,div的摆放方向(left,right),div的摆放位置,div层距顶部的位置,显示的图片数组变量)
function showImageDiv(div,pos,posPX,topPx,imageArray){
var j;
document.write("<div id=\"" + div + "\" style=\"" + pos + ":" + posPX + "px;POSITION:absolute;TOP:" + topPx + "px;\">");
for(j=0; j< imageArray.length; j++){
document.write("<a href=\"" + imageArray[j][0] + "\" "+ imageArray[j][2]+ imageArray[j][3] + "><img src=\""+ imageArray[j][1] + "\" border=\"0\" "+ imageArray[j][3] + "></a>");
if(j != imageArray.length-1){document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=10></td></tr></table>");}
}
document.write("</div>");
}
//滚动广告对联图片
this.scroll = function(){
showImageDiv("smilediv1","left",leftPos,leftTop,leftImageArray);
showImageDiv("smilediv2","right",rightPos,rightTop,rightImageArray);
window.setInterval(scrollImage,1);
}
//内部使用用来滚动广告图片
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;
}
}
///////////////////////////////////////////类结束////////////////////////////////////////////////////////////////
/////////类的使用示例代码////////////////////////////////////////////////
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();
//& 作者: 哇哇鱼
//& 日期: 2004年12月31日
//& 网站: http://www.13smile.com/
//& Blog: http://blog.csdn.net/bpfish
//& 名称: [对联广告] JS脚本类
//& 作用: 显示页面的对联广告
//& 方法:
//& SmileAdver.setLeftPos(10); //设置左边对联的距页面左边的位置(PX)
//& SmileAdver.setLeftTop(150); //设置左边对联的距页面顶部的位置(PX)
//& SmileAdver.setRightPos(10); //设置右边对联的距页面右边的位置(PX)
//& SmileAdver.setRightTop(150); //设置右边对联的距页面顶部的位置(PX)
//& SmileAdver.addLeftImage(链接,图片地址,链接目标,图片提示); //添加左边对联广告的图片
//& SmileAdver.addRightImage(链接,图片地址,链接目标,图片提示); //添加右边对联广告的图片
//& SmileAdver.scroll(); //显示对联广告
//&
//****************************************************************************************
function SmileAdver_Class(){
var leftImageArray = new Array(); //保存左边的广告图片数组
var rightImageArray = new Array(); //保存右边的广告图片数组
var leftPos,rightPos; //leftPos = 左边广告的距左边栏位置(px) rightPos = 右边广告的距右边栏位置(px)
var leftTop,rightTop; //leftTop = 左边广告的距顶边栏位置(px) rightTop = 右边广告的距顶边栏位置(px)
var lastScrollY=0;
leftPos = rightPos = 10; //默认为10
leftTop = rightTop = 150; //默认为150
this.setLeftPos = function(value){
if(isNaN(value)){value = 10;} //非数字则默认为10
leftPos = value;
}
this.setRightPos = function(value){
if(isNaN(value)){value = 10;} //非数字则默认为10
rightPos = value;
}
this.setLeftTop = function(value){
if(isNaN(value)){value = 150;} //非数字则默认为150
leftTop = value;
}
this.setRightTop = function(value){
if(isNaN(value)){value = 150;} //非数字则默认为150
rightTop = value;
}
//添加左边的图片广告 addLeftImage(链接,图片地址,链接目标,图片提示)
this.addLeftImage = function(href,image,target,title){
var imageArray = getImageArray(href,image,target,title);
if(imageArray != null){
leftImageArray[leftImageArray.length] = imageArray;
}
}
//添加右边的图片广告 addRightImage(链接,图片地址,链接目标,图片提示)
this.addRightImage = function(href,image,target,title){
var imageArray = getImageArray(href,image,target,title);
if(imageArray != null){
rightImageArray[rightImageArray.length] = imageArray;
}
}
//内部添加广告图片使用,如果没有图片地址,则返回一个null值,否则返回一个数组
function getImageArray(href,image,target,title){
if(image == undefined){return null;} //没有图片地址,不添加
if(target == undefined || target == ""){target = "_blank"}; //默认为_blank打开方式
target = " target=\"" + target + "\"";
if(title == undefined){ //广告图片title提示
title = "" ;
}else{
title = " title=\"" + title + "\"";
}
//链接以www.开头则自动加上http:// (否则链接时会链接错误)
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);
}
//内部显示图片横幅所用 showImageDiv(div的名称,div的摆放方向(left,right),div的摆放位置,div层距顶部的位置,显示的图片数组变量)
function showImageDiv(div,pos,posPX,topPx,imageArray){
var j;
document.write("<div id=\"" + div + "\" style=\"" + pos + ":" + posPX + "px;POSITION:absolute;TOP:" + topPx + "px;\">");
for(j=0; j< imageArray.length; j++){
document.write("<a href=\"" + imageArray[j][0] + "\" "+ imageArray[j][2]+ imageArray[j][3] + "><img src=\""+ imageArray[j][1] + "\" border=\"0\" "+ imageArray[j][3] + "></a>");
if(j != imageArray.length-1){document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td height=10></td></tr></table>");}
}
document.write("</div>");
}
//滚动广告对联图片
this.scroll = function(){
showImageDiv("smilediv1","left",leftPos,leftTop,leftImageArray);
showImageDiv("smilediv2","right",rightPos,rightTop,rightImageArray);
window.setInterval(scrollImage,1);
}
//内部使用用来滚动广告图片
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;
}
}
///////////////////////////////////////////类结束////////////////////////////////////////////////////////////////
/////////类的使用示例代码////////////////////////////////////////////////
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();
上一篇:Ajax异步文件上传与NodeJS express服务端处理
栏 目:JavaScript代码
下一篇:js实现上传图片到服务器
本文标题:[对联广告] JS脚本类
本文地址:http://www.codeinn.net/misctech/166894.html