纯JS代码编写顶飘,底飘固定位代码分享
代码如下:
<script>
//原生javascript首尾固定广告

// 关闭函数
function closead(Obj){
Obj.parentNode.parentNode.removeChild(Obj.parentNode);
}
window.onload = function(){
// 顶部固定
var top = document.createElement("div");
top.id = 'top';
top.setAttribute("style","position: fixed;z-index: 999999;top: 0;height: 80px;right: 0;left: 0;");
top.innerHTML = '<span onclick="closead(this)" style="cursor: pointer; height: 20px; width: 20px; position: absolute; z-index: 2147483647; display: block; border-radius: 10px; background: rgba(102, 102, 102, 0.7); font-size: 11px; color: rgb(255, 255, 255); text-align: center; line-height: 20px; right: 6px; top: 6px;">X</span><a href="广告链接" style="display: block; height: 100px;"><img src="http://www.02516.com/upload/pic/201991611721414.gif"/ width="100%" height="100%"></a>';
// 底部固定
var bottom = document.createElement("div");
bottom.id = 'bottom';
bottom.setAttribute("style","position: fixed;z-index: 999999; bottom: 0;height: 80px;right: 0;left: 0;");
bottom.innerHTML = '<span onclick="closead(this)" style="cursor: pointer; height: 20px; width: 20px; position: absolute; z-index: 2147483647; display: block; border-radius: 10px; background: rgba(102, 102, 102, 0.7); font-size: 11px; color: rgb(255, 255, 255); text-align: center; line-height: 20px; right: 6px; top: 6px;">X</span><a href="广告链接" style="display: block; height: 100px;"><img src="http://www.02516.com/upload/pic/201991611721414.gif"/ width="100%" height="100%"></a>';
document.getElementsByTagName("body")[0].appendChild(top);
document.getElementsByTagName("body")[0].appendChild(bottom);
}
</script>

 

本文标题:纯JS代码编写顶飘,底飘固定位代码分享
本文链接:https://www.lengxi.net/post/375.html
作者授权:除特别说明外,本文由 冷曦 原创编译并授权 冷曦博客 - 源码之家 刊载发布。
版权声明:本文不使用任何协议授权,您可以任何形式自由转载或使用。

暂无留言,赶快评论吧

欢迎留言