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

首頁 > 編程 > JavaScript > 正文

javascript AutoScroller 函數類

2019-11-21 01:20:44
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

/*
* Copyright (C) 2007-2009 skylark
* Email:aohailin@gmail.com
* Version:2.1
* 原創程序,轉載請保留版權
*/
var $=function(o){return typeof o=="string"?document.getElementById(o):o;};
function AutoScroll(){
this.obj=[];
this.version="2.1";
this.Build();//初始化
};
AutoScroll.prototype.Build=function(){
var me=this;
//取得其他滾動事件
var oldscroll=window.onscroll;
window.onscroll=function(){
//保護其他滾動事件
if("function"==typeof oldscroll){
oldscroll();
}
//得到客戶端瀏覽器參數,兼容IE,FF,Chrome
this.common={
t:document.documentElement.scrollTop||document.body.scrollTop,
h:document.documentElement.clientHeight||document.body.clientHeight,
w:document.documentElement.clientWidth||document.body.clientWidth
};
this.position=[];
for(var i=0;i<me.obj.length;i++){
try{
this.style={};
//獲得客戶端位置,設置了7種位置
//為了讓最小化自動適應位置,這里動態計算位置,所以滾動事件觸發時,CPU消耗很大
this.position[i]=[
{x:0,y:this.common.t},
{x:this.common.w-me.obj[i].obj.offsetWidth,y:this.common.t},
{x:0,y:(this.common.h+this.common.t-me.obj[i].obj.offsetHeight)/2+(this.common.t)/2},
{x:this.common.w-me.obj[i].obj.offsetWidth,y:(this.common.h+this.common.t-me.obj[i].obj.offsetHeight)/2+(this.common.t)/2},
{x:(this.common.w-me.obj[i].obj.offsetWidth)/2,y:(this.common.h+this.common.t-me.obj[i].obj.offsetHeight)/2+(this.common.t)/2},
{x:0,y:this.common.h+this.common.t-me.obj[i].obj.offsetHeight},
{x:this.common.w-me.obj[i].obj.offsetWidth,y:this.common.h+this.common.t-me.obj[i].obj.offsetHeight}
];
//處理自定義樣式
this.style="object"==typeof me.obj[i].style?{x:me.obj[i].style.left,y:me.obj[i].style.top+this.common.t}:{x:this.position[i][me.obj[i].style].x,y:this.position[i][me.obj[i].style].y};
//定位
me.obj[i].obj.style.left=this.style.x+"px";
me.obj[i].obj.style.top=this.style.y+"px";
}catch(e){
//功能是過濾無效obj
for(var j=i;j<me.obj.length-1;j++){
me.obj[j]=me.obj[j+1];
me.obj.length=me.obj.length-1;
}
}
}
};
//初始化
window.scroll(1,1);
};
AutoScroll.prototype.Add=function(){
var obj=arguments[0];
//獲得當前position
var oldposition=$(obj.id).style.position;
$(obj.id).style.position="absolute";
//不使用fixed,雖然高版本瀏覽器都已經支持fixed
this.obj.push({
obj:$(obj.id),
oldposition:oldposition,
style:obj.style
});
};
AutoScroll.prototype.Remove=function(){
var obj=arguments[0];
for(var i=0;i<this.obj.length;i++){
if(this.obj[i].obj==$(obj.id)){
//還原初始狀態position
this.obj[i].obj.style.position=this.obj[i].oldposition;
//是否真正移除
if(obj.remove){
this.obj[i].obj.innerHTML="";
document.body.removeChild(this.obj[i].obj);
}
//移除obj
for(var j=i;j<this.obj.length-1;j++){
this.obj[j]=this.obj[j+1];
}
this.obj.length=this.obj.length-1;
break;
}
}
};
var Scroller=new AutoScroll();
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台南县| 新密市| 钦州市| 洛浦县| 广州市| 大理市| 兰西县| 灵山县| 栾城县| 定结县| 扶余县| 革吉县| 巴楚县| 碌曲县| 方正县| 车致| 丰宁| 咸丰县| 金寨县| 岳普湖县| 英吉沙县| 宜黄县| 高台县| 枣庄市| 特克斯县| 云安县| 徐水县| 陵川县| 平湖市| 扶沟县| 田阳县| 垫江县| 布尔津县| 天镇县| 锡林郭勒盟| 邯郸县| 富宁县| 晋中市| 出国| 长宁区| 江川县|