js对联广告代码,兼容性高
var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined)) }, getWindow: function () { var myHeight = 0; var myWidth = 0; if (typeof (window.innerWidth) == 'number') { myHeight = window.innerHeight; myWidth = window.innerWidth } else if (document.documentElement) { myHeight = document.documentElement.clientHeight; myWidth = document.documentElement.clientWidth } else if (document.body) { myHeight = document.body.clientHeight; myWidth = document.body.clientWidth } return { 'height': myHeight, 'width': myWidth} }, getScroll: function () { var myHeight = 0; var myWidth = 0; if (typeof (window.pageYOffset) == 'number') { myHeight = window.pageYOffset; myWidth = window.pageXOffset } else if (document.documentElement) { myHeight = document.documentElement.scrollTop; myWidth = document.documentElement.scrollLeft } else if (document.body) { myHeight = document.body.scrollTop; myWidth = document.body.scrollLeft } return { 'height': myHeight, 'width': myWidth} }, getDocWidth: function (D) { if (!D) var D = document; return Math.max(Math.max(D.body.scrollWidth, D.documentElement.scrollWidth), Math.max(D.body.offsetWidth, D.documentElement.offsetWidth), Math.max(D.body.clientWidth, D.documentElement.clientWidth)) }, getDocHeight: function (D) { if (!D) var D = document; return Math.max(Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight)) } }; var dom = { ID: function (id) { var type = typeof (id); if (type == 'object') return id; if (type == 'string') return document.getElementById(id); return null }, insertHtml: function (html) { var frag = document.createDocumentFragment(); var div = document.createElement("div"); div.innerHTML = html; for (var i = 0, ii = div.childNodes.length; i < ii; i++) { frag.appendChild(div.childNodes[i]) } document.body.insertBefore(frag, document.body.firstChild) } }; var myEvent = { add: function (element, type, handler) { var ele = dom.ID(element); if (!ele) return; if (ele.addEventListener) ele.addEventListener(type, handler, false); else if (ele.attachEvent) ele.attachEvent("on" + type, handler); else ele["on" + type] = handler }, remove: function (element, type, handler) { var ele = dom.ID(element); if (!ele) return; if (ele.removeEventListener) ele.removeEventListener(type, handler, false); else if (ele.detachEvent) ele.detachEvent("on" + type, handler); else ele["on" + type] = null } }; var position = { rightCenter: function (id) { var id = dom.ID(id); var ie6 = browser.ie6(); var win = browser.getWindow(); var ele = { 'height': id.clientHeight, 'width': id.clientWidth }; if (ie6) { var scrollBar = browser.getScroll() } else { var scrollBar = { 'height': 0, 'width': 0 }; id.style.position = 'fixed' } ele.top = parseInt((win.height - ele.height) / 2 + scrollBar.height); id.style.top = ele.top + 'px'; id.style.right = '3px' }, floatRightCenter: function (id) { position.rightCenter(id); var fun = function () { position.rightCenter(id) }; if (browser.ie6()) { myEvent.add(window, 'scroll', fun); myEvent.add(window, 'resize', fun) } else { myEvent.add(window, 'resize', fun) } }, leftCenter: function (id) { var id = dom.ID(id); var ie6 = browser.ie6(); var win = browser.getWindow(); var ele = { 'height': id.clientHeight, 'width': id.clientWidth }; if (ie6) { var scrollBar = browser.getScroll() } else { var scrollBar = { 'height': 0, 'width': 0 }; id.style.position = 'fixed' } ele.top = parseInt((win.height - ele.height) / 2 + scrollBar.height); id.style.top = ele.top + 'px'; id.style.left = '3px' }, floatLeftCenter: function (id) { position.leftCenter(id); var fun = function () { position.leftCenter(id) }; if (browser.ie6()) { myEvent.add(window, 'scroll', fun); myEvent.add(window, 'resize', fun) } else { myEvent.add(window, 'resize', fun) } } };
function ad_left() {
var html;
html = '<div id="ad_left" style="position:absolute;width:100px;height:300px;z-index:10001"><a style="position:absolute;top:-15px;left:0;" href="javascript:void(0);" onclick="document.getElementById(\'ad_left\').style.display=\'none\'">关闭</a><a href="http://www.xiaotouchengxu.com/" target=_blank><img src="http://www.xiaotouchengxu.com/ad/x1.gif" width="100" height="300" /></a></div>';
dom.insertHtml(html); position.floatLeftCenter('ad_left');
}
function ad_right() {
var html;
html = '<div id="ad_right" style="position:absolute;width:100px;height:300px;z-index:10001"><a style="position:absolute;top:-15px;right:0;" href="javascript:void(0);" onclick="document.getElementById(\'ad_right\').style.display=\'none\'">关闭</a><a href="http://www.xiaotouchengxu.com/" target=_blank><img src="http://www.xiaotouchengxu.com/ad/x1.gif" width="100" height="300" /></a></div>';
dom.insertHtml(html); position.floatRightCenter('ad_right');
}
myEvent.add(window, 'load', ad_left);
myEvent.add(window, 'load', ad_right);
js对联广告代码,兼容性高的更多相关文章
- Js浮动广告效果实现
第一种 漂浮广告 不符合W3CJavaScript漂浮广告代码,很不错,代码精简,不过一次只有漂一个,复制就能用了.希望站长朋友喜欢. <html> <head> <ti ...
- JavaScript浮动广告代码,容纯DIV/CSS对联漂浮广告代码,兼容性非常好的js右下角与漂浮广告代码
基于JavaScript代码实现随机漂浮图片广告,javascript图片广告 在网上有很多这样的代码,不过未必符合W3C标准,因为在头部加上<!DOCTYPE html>类似标签之后,漂 ...
- JS使用cookie实现只出现一次的广告代码效果
我们上网经常会遇到第一次需要登录而之后不用再登录的网站的情况,其实是运用了Cookie 存储 web 页面的用户信息,Cookie 以名/值对形式存储,当浏览器从服务器上请求 web 页面时, 属于该 ...
- Js弹性漂浮广告代码
<html><head><meta http-equiv="Content-Type" content="text/html; charse ...
- 使用cookie实现只出现一次的广告代码效果
我们上网经常会遇到第一次需要登录而之后不用再登录的网站的情况,其实是运用了Cookie 存储 web 页面的用户信息,Cookie 以名/值对形式存储,当浏览器从服务器上请求 web 页面时, 属于该 ...
- js右下角弹窗代码(实测好用)
实测好用的js右下角弹窗代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "htt ...
- js获取隐藏元素宽高的方法
网上有一些js获取隐藏元素宽高的方法,但是可能会存在某些情况获取不了. 例如: <!DOCTYPE html> <html lang="en"> <h ...
- 关于JS的一些代码效果图
关于JS的一些代码效果图 1.几乎所有DOM元素都有innerText.innerHTML属性(注意大小写),分别是元素标签内内容的文本表示形式和HTML源代码,这两个属性是可读可写的. 需要注意的是 ...
- [转]javascript对联广告、漂浮广告封装类,多浏览器兼容
封装的JS方法: function $$(element){ if(arguments.length>1){ for(var i=0,elements=[],length=arguments.l ...
随机推荐
- android 开发上传图片遇到返回 FileNotFoundException
目的:带有参数上传图片 环境:客户端开发 android studio ,服务器端:visual studio 2012 (c# asp.net) ************************* ...
- .Xresources 配置文件
安装rxvt-unicode-256color,如果不是这个版本的话VIM配色会显示不正常. ~/.Xresources配置文件如下 !urxvt color scheme: URxvt*backgr ...
- SHELL syntax error:unexpected end of file 提示错误
SHELL syntax error:unexpected end of file 提示错误 if [ -n "$1" ] then " else " fi e ...
- PHP的反射机制(转)
介绍: PHP5添加了一项新的功能:Reflection.这个功能使得phper可以reverse-engineer class, interface,function,method and exte ...
- java内存分配详细论
P.S. 想写这篇总结酝酿了有个来月了,却始终感觉还差点什么东西,一直未敢动笔. 最近两天连夜奋战,重新整理下前面查阅的资料.笔记,还是决定将它写出来. 现在提出几个问题,如果都能熟练回答的大虾,请您 ...
- Volatile 说明
Java™ 语言包含两种内在的同步机制:同步块(或方法)和 volatile 变量.这两种机制的提出都是为了实现代码线程的安全性.其中 Volatile 变量的同步性较差(但有时它更简单并且开销更低) ...
- hdoj 1596 find the safest road
题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=1596 分析:Dijkstra变体,最短路径判断计算方式:Safe(P) = s(e1)*s(e2)…* ...
- 2013 Multi-University Training Contest 1 3-idiots
解题报告: 记录 A_i 为长度为 i 的树枝的数量,并让 A 对它本身做 FFT,得到任意选两个树枝能得到的各个和的数量.枚举第三边, 计算出所有两边之和大于第三条边的方案数,并把前两条边包含最长边 ...
- 2013 Multi-University Training Contest 1 I-number
水题,注意不要去掉前导0…… ;}
- lintcode:anagrams 乱序字符串
题目 乱序字符串 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 您在真实的面试中是否遇到过这个 ...