数码资讯
图片按钮开关的本地Javascript实现
首先给你看显示器的结果。 下面是详细的代码: 复制代码代码如下所示: 功能lgy_picswitch(选项){ this.owrap = this.getid(选项。wrapid); / /外元 this.olistwrap = this.getnodebyclassname(这个。owrap,'g
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
首先给你看显示器的结果。
下面是详细的代码:
复制代码代码如下所示:
功能lgy_picswitch(选项){
this.owrap = this.getid(选项。wrapid); / /外元
this.olistwrap = this.getnodebyclassname(这个。owrap,'gy_picswitch_listwrap){ 0 };
this.oul = this.olistwrap.getelementsbytagname('ul){ 0 };
this.obtnprev = this.getnodebyclassname(这个。owrap,'gy_picswitch_prev){ 0 };
this.obtnnext = this.getnodebyclassname(这个。owrap,'gy_picswitch_next){ 0 };
this.nlen = this.oul.getelementsbytagname(李。长度); / /总的照片
this.nscollcount = option.scrollcount; / /每卷
this.nscolllen = math.ceil(这。nlen /选项。scrollcount); / /最大切换判决
this.nswitchwidth = 0; / /每次移动的距离,得到动态代码的价值
this.nindex = 0; / /当前索引画面切换
this.timer = null; / /索引值切换画面
This.int();
}
lgy_picswitch.prototype = { {
GetId:功能(ID){
返回document.getelementbyid(ID);
},
getnodebyclassname:功能(父母,className){
无功classelements =新的数组();
VaR ELS = parent.getelementsbytagname(*);
无功elslen = els.length;
VAR模式= new RegExp((^ | S)+类名+(的| $ ));
为(i = 0,J = 0;i < elslen;i++){
如果(pattern.test(ELS {我}。className)){
classelements { } = {我} ELS {J}.;
++;
}
}
返回classelements;
},
GetCss:功能(节点值)
{
返回节点。currentstylenode。currentstyle {value}:getcomputedstyle(节点,null){价值};
},
setcss:功能(节点,Val){
对于(var中的var){
node.style.csstext + =V+瓦尔{五};
}
},
MoveFn:功能(节点值,目标值,回调){
无功_that =这;
ClearInterval(这个定时器);
this.timer = setInterval(function())
{
VaR值= parseFloat(_that.getcss(节点值));
速度=(目标值-缬氨酸) / 8;
速度=速度> 0math.ceil(速度):Math.floor(速度);
如果(速度= 0)
{
ClearInterval(_that。定时器);
Callbackcallback();
}
其他的
{
节点。风格{value} =(Val +速度)+ 'px;
}
},20);
},
PicChange:函数(){
This.moveFn(,,,'marginleft ',这,这nswitchwidth nIndex。);
},
cancelbubble:功能(e){
e.stoppropagatione.stoppropagation():e.cancelbubble =真;
},
BtnIsShow:函数(){
This.setCss(this.obtnnext,{显示:阻止});
This.setCss(this.obtnprev,{显示:阻止});
如果(this.nindex = 0)和this.setcss(this.obtnprev,{显示器:不关});
如果(this.nindex =(本。nscolllen-1)this.setcss(这个。obtnnext),{显示器:不关});
},
BtnPrev:函数(){
无功_that =这;
this.obtnprev.onclick =功能(e){
VaR E = e window.event | |;
_that.cancelbubble(E);
如果(_that.nindex!= 0){
_that.nindex--;
_that.picchange();
_that.btnisshow();
}
}
},
BtnNext:函数(){
无功_that =这;
this.obtnnext.onclick =功能(e){
VaR E = e window.event | |;
_that.cancelbubble(E);
如果(_that.nindex!=(_that。nscolllen-1)){
_that nIndex + +;
_that.picchange();
_that.btnisshow();
}
}
},
Int:函数(){
移动访问的动态访问宽度
VaR OLI = this.oul.getelementsbytagname(李){ 0 },
oli_w = oli.offsetwidth + parseInt(this.getcss(OLI,'marginleft'))+ parseInt(this.getcss(OLI,'marginright '));
this.nswitchwidth = oli_w * this.nscollcount;
按钮/显示初始化
This.btnIsShow();
关于开关
This.btnPrev();
This.btnNext();
}
}
HTML代码:
复制代码代码如下所示:
*
* HTML结构必须遵循:外部标识名称,引入如下:ID =gy_picswitch02
然而,在它的结构必须相同,包括类名类名
参数:'wrapid:'xxxx ',最外层的ID名字
scrollcount:5、碾压次数
复制代码代码如下所示:
*
* /
实例化
新的lgy_picswitch({ 'wrapid:'gy_picswitch ','scrollcount:5 });
是一个很方便的功能,使用起来也很简单,这是推荐给小伙伴的,希望对大家有帮助。
下面是详细的代码:
复制代码代码如下所示:
功能lgy_picswitch(选项){
this.owrap = this.getid(选项。wrapid); / /外元
this.olistwrap = this.getnodebyclassname(这个。owrap,'gy_picswitch_listwrap){ 0 };
this.oul = this.olistwrap.getelementsbytagname('ul){ 0 };
this.obtnprev = this.getnodebyclassname(这个。owrap,'gy_picswitch_prev){ 0 };
this.obtnnext = this.getnodebyclassname(这个。owrap,'gy_picswitch_next){ 0 };
this.nlen = this.oul.getelementsbytagname(李。长度); / /总的照片
this.nscollcount = option.scrollcount; / /每卷
this.nscolllen = math.ceil(这。nlen /选项。scrollcount); / /最大切换判决
this.nswitchwidth = 0; / /每次移动的距离,得到动态代码的价值
this.nindex = 0; / /当前索引画面切换
this.timer = null; / /索引值切换画面
This.int();
}
lgy_picswitch.prototype = { {
GetId:功能(ID){
返回document.getelementbyid(ID);
},
getnodebyclassname:功能(父母,className){
无功classelements =新的数组();
VaR ELS = parent.getelementsbytagname(*);
无功elslen = els.length;
VAR模式= new RegExp((^ | S)+类名+(的| $ ));
为(i = 0,J = 0;i < elslen;i++){
如果(pattern.test(ELS {我}。className)){
classelements { } = {我} ELS {J}.;
++;
}
}
返回classelements;
},
GetCss:功能(节点值)
{
返回节点。currentstylenode。currentstyle {value}:getcomputedstyle(节点,null){价值};
},
setcss:功能(节点,Val){
对于(var中的var){
node.style.csstext + =V+瓦尔{五};
}
},
MoveFn:功能(节点值,目标值,回调){
无功_that =这;
ClearInterval(这个定时器);
this.timer = setInterval(function())
{
VaR值= parseFloat(_that.getcss(节点值));
速度=(目标值-缬氨酸) / 8;
速度=速度> 0math.ceil(速度):Math.floor(速度);
如果(速度= 0)
{
ClearInterval(_that。定时器);
Callbackcallback();
}
其他的
{
节点。风格{value} =(Val +速度)+ 'px;
}
},20);
},
PicChange:函数(){
This.moveFn(,,,'marginleft ',这,这nswitchwidth nIndex。);
},
cancelbubble:功能(e){
e.stoppropagatione.stoppropagation():e.cancelbubble =真;
},
BtnIsShow:函数(){
This.setCss(this.obtnnext,{显示:阻止});
This.setCss(this.obtnprev,{显示:阻止});
如果(this.nindex = 0)和this.setcss(this.obtnprev,{显示器:不关});
如果(this.nindex =(本。nscolllen-1)this.setcss(这个。obtnnext),{显示器:不关});
},
BtnPrev:函数(){
无功_that =这;
this.obtnprev.onclick =功能(e){
VaR E = e window.event | |;
_that.cancelbubble(E);
如果(_that.nindex!= 0){
_that.nindex--;
_that.picchange();
_that.btnisshow();
}
}
},
BtnNext:函数(){
无功_that =这;
this.obtnnext.onclick =功能(e){
VaR E = e window.event | |;
_that.cancelbubble(E);
如果(_that.nindex!=(_that。nscolllen-1)){
_that nIndex + +;
_that.picchange();
_that.btnisshow();
}
}
},
Int:函数(){
移动访问的动态访问宽度
VaR OLI = this.oul.getelementsbytagname(李){ 0 },
oli_w = oli.offsetwidth + parseInt(this.getcss(OLI,'marginleft'))+ parseInt(this.getcss(OLI,'marginright '));
this.nswitchwidth = oli_w * this.nscollcount;
按钮/显示初始化
This.btnIsShow();
关于开关
This.btnPrev();
This.btnNext();
}
}
HTML代码:
复制代码代码如下所示:
*
* HTML结构必须遵循:外部标识名称,引入如下:ID =gy_picswitch02
然而,在它的结构必须相同,包括类名类名
参数:'wrapid:'xxxx ',最外层的ID名字
scrollcount:5、碾压次数
复制代码代码如下所示:
*
* /
实例化
新的lgy_picswitch({ 'wrapid:'gy_picswitch ','scrollcount:5 });
是一个很方便的功能,使用起来也很简单,这是推荐给小伙伴的,希望对大家有帮助。
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。