国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js 居中漂浮廣告

2024-05-06 14:10:52
字體:
來源:轉載
供稿:網友
程序源碼
代碼如下:
var floatAd = {};
floatAd.getScrollTop = function(node) {
var doc = node ? node.ownerDocument : document;
return doc.documentElement.scrollTop || doc.body.scrollTop;
};
floatAd.getScrollLeft = function(node) {
var doc = node ? node.ownerDocument : document;
return doc.documentElement.scrollLeft || doc.body.scrollLeft;
};
floatAd.getBrowser = function() {
var d = document.documentElement;
return {
width: window.innerWidth || (d && d.clientWidth) || document.body.clientWidth,
height: window.innerHeight || (d && d.clientHeight) || document.body.clientHeight
}
};
floatAd.extend = function(destination, source) {
for(var property in source) {
destination[property] = source[property];
}
return destination;
};
/* 默認屬性擴展 */
floatAd.setOptions = function(options) {
this.options = {
delay: 20, // 調整速率
fadeTime: 1 // 自動消失時間
};
return this.extend(this.options, options || {});
};
/* 類初始化 */
floatAd.init = function(id, options) {
var _this = this;
this.extend(this, this.setOptions(options));
this.control = document.getElementById(id);
var _callback = function() { // fadeIn完成后的回調函數
_this.timer = window.setInterval(function() { _this.scroll() }, _this.delay); // 滾動定位
window.setTimeout(function() { _this.fadeOut() }, _this.fadeTime * 1000); // 在固定時間內消失
}
this.fadeIn(_callback);
window.onresize = function() { _this.setCenter(); }
};
/* 定時滾動 */
floatAd.scroll = function() {
this.start = parseInt(this.control.style.top, 10);
this.end = parseInt(this.getScrollTop() + this.getBrowser().height - this.control.clientHeight, 10);
if(this.start != this.end) {
this.amount = Math.ceil(Math.abs(this.end - this.start) / 15); /* 遞減公式(this.start無限增大,整個分子無限減小,整個值就無限趨近于0) */
this.control.style.top = parseInt(this.control.style.top, 10) + ((this.end < this.start) ? -this.amount : this.amount) + 'px';
}
};
/* 目標居中并處于最底部 */
floatAd.setCenter = function() {
this.top = this.getScrollTop() + floatAd.getBrowser().height;
this.left = (this.getScrollLeft() + floatAd.getBrowser().width - this.control.clientWidth) / 2;
this.control.style.top = this.top + 'px';
this.control.style.left = this.left + 'px';
};
/* fadeIn */
floatAd.fadeIn = function(callback) {
var _this = this, _top = 0;
this.control.style.display = 'block'; // *要提前顯示.不然無法取得clientWidth
this.setCenter();
var _timer = window.setInterval(function() {
_this.control.style.top = _this.getScrollTop() + _this.getBrowser().height - (++_top) + 'px';
if(_top >= _this.control.clientHeight) {
window.clearInterval(_timer);
callback && callback();
}
}, 2);
};
/* fadeOut */
floatAd.fadeOut = function() {
var _this = this, _num = 0, _top = _this.control.clientHeight;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 吴川市| 丽江市| 忻州市| 彰武县| 苍南县| 齐齐哈尔市| 武功县| 礼泉县| 漳浦县| 东兰县| 沙雅县| 永寿县| 长武县| 周口市| 仙桃市| 依安县| 民勤县| 绥江县| 罗平县| 息烽县| 红河县| 宁安市| 奉新县| 保山市| 阿勒泰市| 伊春市| 濮阳县| 灌阳县| 辛集市| 桓台县| 秦皇岛市| 和林格尔县| 中宁县| 长汀县| 石渠县| 北京市| 荆门市| 云阳县| 呼和浩特市| 宁南县| 油尖旺区|