//公共脚本文件 main.js function addevent(obj, evttype, func, cap) { cap = cap || false; if (obj.addeventlistener) { obj.addeventlistener(evttype, func, cap); return true; } else if (obj.attachevent) { if (cap) { obj.setcapture(); return true; } else { return obj.attachevent("on" + evttype, func); } } else { return false; } } function removeevent(obj, evttype, func, cap) { cap = cap || false; if (obj.removeeventlistener) { obj.removeeventlistener(evttype, func, cap); return true; } else if (obj.detachevent) { if (cap) { obj.releasecapture(); return true; } else { return obj.detachevent("on" + evttype, func); } } else { return false; } } function getpagescroll() { var xscroll, yscroll; if (self.pagexoffset) { xscroll = self.pagexoffset; } else if (document.documentelement && document.documentelement.scrollleft) { xscroll = document.documentelement.scrollleft; } else if (document.body) { xscroll = document.body.scrollleft; } if (self.pageyoffset) { yscroll = self.pageyoffset; } else if (document.documentelement && document.documentelement.scrolltop) { yscroll = document.documentelement.scrolltop; } else if (document.body) { yscroll = document.body.scrolltop; } arraypagescroll = new array(xscroll, yscroll); return arraypagescroll; } // 获取页面的高度、宽度 function getpagesize() { var xscroll, yscroll; if (window.innerheight && window.scrollmaxy) { xscroll = window.innerwidth + window.scrollmaxx; yscroll = window.innerheight + window.scrollmaxy; } else { if (document.body.scrollheight > document.body.offsetheight) { // all but explorer mac xscroll = document.body.scrollwidth; yscroll = document.body.scrollheight; } else { // explorer mac...would also work in explorer 6 strict, mozilla and safari xscroll = document.body.offsetwidth; yscroll = document.body.offsetheight; } } var windowwidth, windowheight; if (self.innerheight) { // all except explorer if (document.documentelement.clientwidth) { windowwidth = document.documentelement.clientwidth; } else { windowwidth = self.innerwidth; } windowheight = self.innerheight; } else { if (document.documentelement && document.documentelement.clientheight) { // explorer 6 strict mode windowwidth = document.documentelement.clientwidth; windowheight = document.documentelement.clientheight; } else { if (document.body) { // other explorers windowwidth = document.body.clientwidth; windowheight = document.body.clientheight; } } } // for small pages with total height less then height of the viewport if (yscroll < windowheight) { pageheight = windowheight; } else { pageheight = yscroll; } // for small pages with total width less then width of the viewport if (xscroll < windowwidth) { pagewidth = xscroll; } else { pagewidth = windowwidth; } arraypagesize = new array(pagewidth, pageheight, windowwidth, windowheight); return arraypagesize; } //广告脚本文件 admove.js /* 例子 加
是为了判断飘窗内容为空时隐藏飘窗
***** content ******
var ad=new admove("div2"); ad.run(); */ //////////////////////////////////////////////////////// var admoveconfig = new object(); admoveconfig.isinitialized = false; admoveconfig.adcount = 0; admoveconfig.scrollx = 0; admoveconfig.scrolly = 0; admoveconfig.movewidth = 0; admoveconfig.moveheight = 0; admoveconfig.resize = function() { var winsize = getpagesize(); admoveconfig.movewidth = winsize[2]; admoveconfig.moveheight = winsize[3]; admoveconfig.scroll(); } admoveconfig.scroll = function() { var winscroll = getpagescroll(); admoveconfig.scrollx = winscroll[0]; admoveconfig.scrolly = winscroll[1]; } addevent(window, "resize", admoveconfig.resize); addevent(window, "scroll", admoveconfig.scroll); function admove(id, addclosebutton) { if (!admoveconfig.isinitialized) { admoveconfig.resize(); admoveconfig.isinitialized = true; } admoveconfig.adcount++; var obj = document.getelementbyid(id); // obj.style.position = "absolute"; obj.style.zindex = "1002"; var w = admoveconfig.movewidth - obj.offsetwidth; var h = admoveconfig.moveheight - obj.offsetheight; var x = w * math.random(), y = h * math.random(); var rad = (math.random() + 1) * math.pi / 6; var kx = math.sin(rad), ky = math.cos(rad); var dirx = (math.random() < 0.5 ? 1 : -1), diry = (math.random() < 0.5 ? 1 : -1); var step = 1; var interval; if (addclosebutton) { var closebtn = document.createelement("span"); closebtn.classname = 'close_btn'; // closebtn.innerhtml="关闭窗口"; closebtn.style.color = "#0040dc"; closebtn.style.cursor = "pointer"; obj.appendchild(closebtn); closebtn.onclick = function() { obj.style.display = "none"; clearinterval(interval); closebtn.onclick = null; obj.onmouseover = null; obj.onmouseout = null; obj.movehandler = null; admoveconfig.adcount--; if (admoveconfig.adcount <= 0) { removeevent(window, "resize", admoveconfig.resize); removeevent(window, "scroll", admoveconfig.scroll); admoveconfig.resize = null; admoveconfig.scroll = null; admoveconfig = null; } } /*判断飘窗内容是否为空,为空就隐藏*/ function removehtmltag(str) { //str = str.replace(/<\/?[^>]*>/g,''); //去除html tag str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白 str = str.replace(/[\r\n]/g, ""); //去除多余空行 str = str.replace(/ /ig, ''); //去掉  return str; } var odiv = obj.getelementsbytagname('div')[0]; if (removehtmltag(odiv.innerhtml) == "") { obj.style.display = "none"; } } obj.movehandler = function() { // obj.style.left = (x + admoveconfig.scrollx) + "px"; // obj.style.top = (y + admoveconfig.scrolly) + "px"; obj.style.left = x + 'px'; obj.style.top = (y) + "px"; rad = (math.random() + 1) * math.pi / 6; w = admoveconfig.movewidth - obj.offsetwidth; h = admoveconfig.moveheight; //-obj.offsetheight; var boxs = document.getelementsbyclassname('advert-box'); if (boxs.length) { var offsetheight = boxs[0].offsetheight; if (h > offsetheight) { h -= offsetheight; } } x = x + step * kx * dirx; if (x < 0) { dirx = 1; x = 0; kx = math.sin(rad); ky = math.cos(rad); } if (x > w) { dirx = -1; x = w; kx = math.sin(rad); ky = math.cos(rad); } y = y + step * ky * diry; if (y < 0) { diry = 1; y = 0; kx = math.sin(rad); ky = math.cos(rad); } if (y > h) { diry = -1; y = h; kx = math.sin(rad); ky = math.cos(rad); } } this.setlocation = function(vx, vy) { x = vx; y = vy; } this.setdirection = function(vx, vy) { dirx = vx; diry = vy; } this.run = function() { var delay = 10; interval = setinterval(obj.movehandler, delay); obj.onmouseover = function() { clearinterval(interval); } obj.onmouseout = function() { interval = setinterval(obj.movehandler, delay); } } }