javascript AutoScroller 函數(shù)類
更新時(shí)間:2009年05月29日 20:33:01 作者:
javascript AutoScroller 自動(dòng)滾動(dòng)類代碼,學(xué)習(xí)類的朋友可以參考下。
復(fù)制代碼 代碼如下:
/*
* Copyright (C) 2007-2009 skylark
* Email:aohailin@gmail.com
* Version:2.1
* 原創(chuàng)程序,轉(zhuǎn)載請(qǐng)保留版權(quán)
*/
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;
//取得其他滾動(dòng)事件
var oldscroll=window.onscroll;
window.onscroll=function(){
//保護(hù)其他滾動(dòng)事件
if("function"==typeof oldscroll){
oldscroll();
}
//得到客戶端瀏覽器參數(shù),兼容IE,F(xiàn)F,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={};
//獲得客戶端位置,設(shè)置了7種位置
//為了讓最小化自動(dòng)適應(yīng)位置,這里動(dòng)態(tài)計(jì)算位置,所以滾動(dòng)事件觸發(fā)時(shí),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){
//功能是過(guò)濾無(wú)效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];
//獲得當(dāng)前position
var oldposition=$(obj.id).style.position;
$(obj.id).style.position="absolute";
//不使用fixed,雖然高版本瀏覽器都已經(jīng)支持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)){
//還原初始狀態(tài)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();
您可能感興趣的文章:
- 深入理解Android中Scroller的滾動(dòng)原理
- Android程序開(kāi)發(fā)之UIScrollerView里有兩個(gè)tableView
- iOS中UIScrollerView的用法及基于AotoLayout的控件懸停
- 詳解Android應(yīng)用開(kāi)發(fā)中Scroller類的屏幕滑動(dòng)功能運(yùn)用
- 詳解Android Scroller與computeScroll的調(diào)用機(jī)制關(guān)系
- jQuery滾動(dòng)條插件nanoscroller使用指南
- android開(kāi)發(fā)之橫向滾動(dòng)/豎向滾動(dòng)的ListView(固定列頭)
- android實(shí)現(xiàn)上下滾動(dòng)的TextView
- Android中實(shí)現(xiàn)多行、水平滾動(dòng)的分頁(yè)的Gridview實(shí)例源碼
- Android Scroller完全解析
相關(guān)文章
js實(shí)現(xiàn)導(dǎo)入導(dǎo)出功能實(shí)例代碼(FileSave.js)
這篇文章主要給大家介紹了關(guān)于js實(shí)現(xiàn)導(dǎo)入導(dǎo)出功能(FileSave.js)的相關(guān)資料,FileSaver.js是在客戶端保存文件的解決方案,非常適合在客戶端上生成文件的Web應(yīng)用,需要的朋友可以參考下2023-11-11
Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁(yè)的實(shí)例
下面小編就為大家?guī)?lái)一篇Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁(yè)的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
js判斷運(yùn)行jsp頁(yè)面的瀏覽器類型以及版本示例
做了一個(gè)判斷瀏覽器類型和版本號(hào)的業(yè)務(wù),記錄下相關(guān)的js代碼,個(gè)人感覺(jué)還不錯(cuò),需要的朋友可以參考下2013-10-10
JavaScript判斷圖片是否已經(jīng)加載完畢的方法匯總
在網(wǎng)上有很多關(guān)于判斷圖片是否已經(jīng)加載完畢的文章,但是有的瀏覽器并不適合,下面小編給大家分享一些有關(guān)JavaScript判斷圖片是否已經(jīng)加載完畢的方法匯總,需要的朋友參考下2016-02-02
JS面試必備之手寫(xiě)call/apply/bind/new
在JavaScript中,call、apply、bind、new是Function對(duì)象自帶的三個(gè)方法,也是面試時(shí)??嫉闹R(shí)點(diǎn),所以本文就來(lái)和大家講講如何手寫(xiě)實(shí)現(xiàn)這四個(gè)方法吧2023-05-05
一些常用且實(shí)用的原生JavaScript函數(shù)
日常開(kāi)始中常用到的一些原生JavaScript函數(shù),比較實(shí)用, 今天特地整理一下,分享給大家,希望對(duì)大家有用,會(huì)常更新,同時(shí)也歡迎大家補(bǔ)充.2010-09-09

