相信很多人知道,现在JavaScript对联广告代码仅靠一些第方广告联盟去生成,似乎是很难了。很多的广告平台都去掉了JavaScript对联广告代码,我们这些站长只能自己来用JavaScript写一个对联广告代码喽,也是非常的简单;
1、html代码
duilian.js是我们调用的JS对联广告代码,后面有一个“?及相关参数”代码是指此JS不让缓存的意思;也可以不跟,看你的需求而定;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./duilian.js?so=fujieace"></script>
</head>
<body>
<p>JS对联广告代码(左侧对联、右侧对联)</p>
</body>
</html>
2、duilian.js代码
下面代码中的"style"样式可以自己根据自己需求来修改,a标签链接和img图片地址也可以随意修改成你自己想要的。
//左侧对联
document.write("<DIV style='position:fixed;float:left;left:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
//右侧对联
document.write("<DIV style='position:fixed;float:right;right:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
或
有时候我们需要判断宽度来显示,可以用以下代码:
//获取分辨率宽度
var iScreenWidth = window.screen.width;
if(iScreenWidth > 1300){
//左侧对联
document.write("<DIV style='position:fixed;float:left;left:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
//右侧对联
document.write("<DIV style='position:fixed;float:right;right:0px;top:215px;'><a href='https://www.fujieace.com/' target='_blank'><img src='https://www.fujieace.com/wp-content/themes/fujie/img/logo.png?x61917'></a></div>");
}
3、JS对联广告代码效果
由于我的这两张图片选择不是很好,可能效果不是很好看,但是功能100%是没有任何问题的。
2020年08月15日 16:01:22 沙发
今天我参考博主这个文章,根据项目需求,我又升级了一下,代码如下: