📄 scroll.js
字号:
function ScrollArea(instName, areaName, totalCnt, perCnt, dispSize, speed, wait) {
this.instName = instName; // 牢胶畔胶疙
this.areaName = areaName; // 捞悼且 康开 div id
this.totalCnt = parseInt(totalCnt); //喉钒 cnt 啊 酒囱 醚 畴免 单捞磐狼 肮荐;
this.perCnt = parseInt(perCnt); //喉钒寸 单捞磐狼 肮荐;
this.curIndex = 0;
this.destIndex = 0;
this.blockCnt = 0; // 歹固甫 力寇茄 鉴荐 喉钒狼 荐
this.dispSize = parseInt(dispSize); // 喉钒狼 臭捞/承捞
this.speed = parseInt(speed); // 捞悼加档 : 努荐废 弧扼咙
if ( this.speed > this.dispSize ) {
this.speed = this.dispSize;
}
this.autospeed = this.speed ;
this.wait = parseInt(wait); // 喉钒 捞悼 饶 措扁 矫埃 milsec, 0 老 版快 磊悼 胶农费 窍瘤 臼绰促.
this.funcName = "";
this.objTimeout = 0;
this.firstCall = true;
this.scroll = true;
/* Set blockCnt */
if ( this.totalCnt == 0 || this.perCnt == 0 ) {
this.blockCnt = 0;
} else {
this.blockCnt = this.totalCnt/this.perCnt;
if ( (""+this.blockCnt).indexOf(".") > -1) {
this.blockCnt = parseInt( (""+this.blockCnt).substring(0,(""+this.blockCnt).indexOf(".")) ) + 1;
}
}
this.setBlockCnt = function(blockCnt) {
this.blockCnt = blockCnt;
}
this.getPosition = function(index) {
return -( index * this.dispSize );
}
/* 胶农费 吝瘤 */
this.scrollStop = function() {
//this.firstCall = true;
//clearTimeout(this.objTimeout);
this.scroll = false;
}
/* 胶农费 犁俺 */
this.scrollContinue = function() {
//this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", 1);
this.scroll = true;
}
/* 酒贰肺 胶农费 */
this.scrollDown = function() {
this.funcName = "scrollDown";
clearTimeout(this.objTimeout);
if ( this.blockCnt == 0 ) return;
if ( this.firstCall ) {
if ( this.curIndex == this.blockCnt ) {
this.curIndex = 0;
document.getElementById(this.areaName).style.top = this.getPosition( this.curIndex ) ;
}
this.destIndex = this.curIndex + 1;
this.firstCall = false;
}
if ( this.scroll ) {
document.getElementById(this.areaName).style.top = parseInt(document.getElementById(this.areaName).style.top) - this.speed;
}
if ( parseInt( document.getElementById(this.areaName).style.top ) < this.getPosition( this.destIndex ) ) {
document.getElementById(this.areaName).style.top = this.getPosition( this.destIndex ) ;
this.curIndex = this.destIndex;
this.firstCall = true;
if ( parseInt(this.wait) > 0 ) {
this.speed = this.autospeed;
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", this.wait);
}
} else {
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", 1);
}
}
/* 困肺 胶农费 */
this.scrollUp = function() {
this.funcName = "scrollUp";
clearTimeout(this.objTimeout);
if ( this.blockCnt == 0 ) return;
if ( this.firstCall ) {
if ( this.curIndex == 0 ) {
this.curIndex = this.blockCnt;
document.getElementById(this.areaName).style.top = this.getPosition( this.curIndex ) ;
}
this.destIndex = this.curIndex - 1;
this.firstCall = false;
}
if ( this.scroll ) {
document.getElementById(this.areaName).style.top = parseInt(document.getElementById(this.areaName).style.top) + this.speed;
}
if ( parseInt( document.getElementById(this.areaName).style.top ) > this.getPosition( this.destIndex ) ) {
document.getElementById(this.areaName).style.top = this.getPosition( this.destIndex ) ;
this.curIndex = this.destIndex;
this.firstCall = true;
if ( parseInt(this.wait) > 0 ) {
this.speed = this.autospeed;
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", this.wait);
}
} else {
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", 1);
}
}
/* 快螟栏肺 胶农费 */
this.scrollRight = function() {
this.funcName = "scrollRight";
clearTimeout(this.objTimeout);
if ( this.blockCnt == 0 ) return;
if ( this.firstCall ) {
if ( this.curIndex == this.blockCnt ) {
this.curIndex = 0;
document.getElementById(this.areaName).style.left = this.getPosition( this.curIndex ) ;
}
this.destIndex = this.curIndex + 1;
this.firstCall = false;
}
if ( this.scroll ) {
document.getElementById(this.areaName).style.left = parseInt(document.getElementById(this.areaName).style.left) - this.speed;
}
if ( parseInt( document.getElementById(this.areaName).style.left ) < this.getPosition( this.destIndex ) ) {
document.getElementById(this.areaName).style.left = this.getPosition( this.destIndex ) ;
this.curIndex = this.destIndex;
this.firstCall = true;
if ( parseInt(this.wait) > 0 ) {
this.speed = this.autospeed;
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", this.wait);
}
} else {
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", 1);
}
}
/* 谅螟栏肺 胶农费 */
this.scrollLeft = function() {
this.funcName = "scrollLeft";
clearTimeout(this.objTimeout);
if ( this.blockCnt == 0 ) return;
if ( this.firstCall ) {
if ( this.curIndex == 0 ) {
this.curIndex = this.blockCnt;
document.getElementById(this.areaName).style.left = this.getPosition( this.curIndex ) ;
}
this.destIndex = this.curIndex - 1;
this.firstCall = false;
}
if ( this.scroll ) {
document.getElementById(this.areaName).style.left = parseInt(document.getElementById(this.areaName).style.left) + this.speed;
}
if ( parseInt( document.getElementById(this.areaName).style.left ) > this.getPosition( this.destIndex ) ) {
document.getElementById(this.areaName).style.left = this.getPosition( this.destIndex ) ;
this.curIndex = this.destIndex;
this.firstCall = true;
if ( parseInt(this.wait) > 0 ) {
this.speed = this.autospeed;
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", this.wait);
}
} else {
this.objTimeout = setTimeout(this.instName + "." + this.funcName + "()", 1);
}
}
/* 滚瓢 努腐矫 坷配 胶农费苞 促弗 加档肺 捞悼 矫懦 版快 */
this.clickDown = function(clickspeed) {
this.speed = parseInt(clickspeed);
this.scrollDown();
}
this.clickUp = function(clickspeed) {
this.speed = parseInt(clickspeed);
this.scrollUp();
}
this.clickLeft = function(clickspeed) {
this.speed = parseInt(clickspeed);
this.scrollLeft();
}
this.clickRight = function(clickspeed) {
this.speed = parseInt(clickspeed);
this.scrollRight();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -