// JavaScript Document var delta = 1; //0.5 //缓冲 1为不缓冲 var collection; function floaters() { this.items = []; this.addItem = function (id, x, y, w, h, content) { document.write('
' + content + '
'); var newItem = {}; newItem.object = document.getElementById(id); newItem.x = x; newItem.y = y; this.items[this.items.length] = newItem; } this.play = function () { collection = this.items setInterval('play()', 10); } } this.play = function play() { l = getscrollLeft(); t = getscrollTop(); if (screen.width <= 0) { for (var i = 0; i < collection.length; i++) { collection[i].object.style.display = 'none'; } return; } for (var i = 0; i < collection.length; i++) { var followObj = collection[i].object; var followObj_x = (typeof (collection[i].x) == 'string' ? eval(collection[i].x) : collection[i].x); var followObj_y = (typeof (collection[i].y) == 'string' ? eval(collection[i].y) : collection[i].y); if (followObj.offsetLeft != (l + followObj_x)) { var dx = (l + followObj_x - followObj.offsetLeft) * delta; dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx)); followObj.style.left = followObj.offsetLeft + dx + "px"; } if (followObj.offsetTop != (t + followObj_y)) { var dy = (t + followObj_y - followObj.offsetTop) * delta; dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy)); followObj.style.top = followObj.offsetTop + dy + "px"; } } function getscrollTop() //得到当前显示内容的高 { if (document.documentElement.scrollTop > 0) { if (document.documentElement.scrollTop > 0) { return document.documentElement.scrollTop } } else { return document.body.scrollTop; } } function getscrollLeft() //得到当前显示内容的宽 { if (document.documentElement.scrollLeft > 0) { if (document.documentElement.scrollLeft > 0) { return document.documentElement.scrollLeft } } else { return document.body.scrollLeft; } } } /* ////////////////////////////// */ var fly_collection; var flyer; function flyers() { var clientW = document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth; var clientH = document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight; this.items = []; this.addItem = function (id, height, width, step, delay, content) { document.write('
' + content + '
'); var newItem = {}; newItem.object = document.getElementById(id); newItem.x = parseInt(Math.random() * (clientW - width) + 1); newItem.y = parseInt(Math.random() * (clientH - height) + 1); newItem.step = step; newItem.delay = delay; newItem.height = height; newItem.width = width; newItem.xSign = newItem.x % 2 == 1 ? 1 : -1; newItem.ySign = newItem.y % 2 == 1 ? 1 : -1; this.items[this.items.length] = newItem; fly_collection = this.items; newItem.object.style.top = newItem.y + "px"; newItem.object.style.left = newItem.x + "px"; } this.play = function () { fly_collection = this.items; flyer = setInterval('playing()', 30); } } function playing(id) { clientW = document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth; clientH = document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight : document.body.clientHeight; scrollT = document.documentElement.scrollTop > 0 ? document.documentElement.scrollTop : document.body.scrollTop; scrollL = document.documentElement.scrollLeft > 0 ? document.documentElement.scrollLeft : document.body.scrollLeft; var isStop = false; if (arguments.length == 1) { isStop = true; } for (i in fly_collection) { if (fly_collection[i].y + fly_collection[i].height >= clientH) { fly_collection[i].ySign = -1; } if (parseInt(fly_collection[i].x) + fly_collection[i].width >= clientW) { fly_collection[i].xSign = -1; } if (parseInt(fly_collection[i].y) <= 0) { fly_collection[i].ySign = 1; } if (parseInt(fly_collection[i].x) <= 0) { fly_collection[i].xSign = 1; } if (!isStop) { fly_collection[i].y = fly_collection[i].y + fly_collection[i].ySign * fly_collection[i].step; fly_collection[i].object.style.top = fly_collection[i].y + scrollT + "px"; fly_collection[i].x = fly_collection[i].x + fly_collection[i].xSign * fly_collection[i].step; fly_collection[i].object.style.left = fly_collection[i].x + scrollL + "px"; } } } function disable(ob) { ob.parentNode.parentNode.removeChild(ob.parentNode); } ////////// //下面注释的为飘动代码 var theFloaters = new floaters(); //*********************左下浮动 theFloaters.addItem('Float2', 5, '75', 115, 175, '
'); //*********************右下浮动 theFloaters.addItem('Float1', '(document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth)-120', '75', 115, 175, '
'); var the_float_x; //浮动的x坐标 the_float_x = 0; theFloaters.play();