如何找出影响HTML图像滑块元素的Javascript部分?
我有一个图像滑块,我试图找出Javascript代码的哪一部分影响HTML元素的实际滑动行为。图像从1-2、2-3滑动,然后通过滑动3-2-1重置。我试着把它设置成只循环幻灯片1-2,2-3,3-1的位置。非常感谢您的帮助 HTML代码:如何找出影响HTML图像滑块元素的Javascript部分?,javascript,html,Javascript,Html,我有一个图像滑块,我试图找出Javascript代码的哪一部分影响HTML元素的实际滑动行为。图像从1-2、2-3滑动,然后通过滑动3-2-1重置。我试着把它设置成只循环幻灯片1-2,2-3,3-1的位置。非常感谢您的帮助 HTML代码: <div id="slideShow"> <!-- module slide_show start //--> <div style="margin:2px 0px 10px 0px;"> <div sty
<div id="slideShow">
<!-- module slide_show start //-->
<div style="margin:2px 0px 10px 0px;">
<div style="overflow: auto; height: 100%; margin: 0px auto;">
<div id="slideWrapper">
<div id="slideItems">
<span><a href="info.php?articles&articles_id=6"><img src="images/about-us.png" alt="" /></a></span>
<span><a href="info.php?articles&articles_id=1"><img src="images/services.png" alt="" /></a></span>
<span><a href="http://www.acehardware.com/acerewards/"><img src="images/ace-rewards.png" alt="" /></a></span>
</div>
</div>
</div>
<script type="text/javascript">
window.addEvent('domready',function(){
var slide_show = new noobSlide({
mode: 'horizontal',items: [0,1,2],size: 960,
box: $('slideItems'),
interval: 10000,
duration: 1000,autoPlay: true});
});</script>
</div>
<!-- module slide_show end //--></div>
addEvent('domready',function(){
var slide_show=新的noobSlide({
模式:“水平”,项目:[0,1,2],大小:960,
方框:$('slideItems'),
间隔:10000,
持续时间:1000,自动播放:true});
});
JAVASCRIPT代码:
/*
Author:
luistar15, <leo020588 [at] gmail.com>
License:
MIT License
Class
noobSlide (rev.19-06-08)
Arguments:
Parameters - see Parameters below
Parameters:
box: dom element | required
items: dom collection | required
size: int | item size (px) | default: 240
mode: string | 'horizontal', 'vertical' | default: 'horizontal'
addButtons:{
previous: single dom element OR dom collection| default: null
next: single dom element OR dom collection | default: null
play: single dom element OR dom collection | default: null
playback: single dom element OR dom collection | default: null
stop: single dom element OR dom collection | default: null
}
button_event: string | event type | default: 'click'
handles: dom collection | default: null
handle_event: string | event type| default: 'click'
fxOptions: object | Fx.Tween options | default: {duration:500,wait:false}
interval: int | for periodical | default: 5000
autoPlay: boolean | default: false
onWalk: event | pass arguments: currentItem, currentHandle | default: null
startItem: int | default: 0
Properties:
box: dom element
items: dom collection
size: int
mode: string
buttons: object
button_event: string
handles: dom collection
handle_event: string
previousIndex: int
nextIndex: int
fx: Fx.Tween instance
interval: int
autoPlay: boolean
onWalk: function
Methods:
previous(manual): walk to previous item
manual: bolean | default:false
next(manual): walk to next item
manual: bolean | default:false
play (interval,direction,wait): auto walk items
interval: int | required
direction: string | "previous" or "next" | required
wait: boolean | required
stop(): stop auto walk
walk(item,manual,noFx): walk to item
item: int | required
manual: bolean | default:false
noFx: boolean | default:false
addHandleButtons(handles):
handles: dom collection | required
addActionButtons(action,buttons):
action: string | "previous", "next", "play", "playback", "stop" | required
buttons: dom collection | required
Requires:
mootools 1.2 core
*/
var noobSlide = new Class({
initialize: function(params){
this.items = params.items;
this.mode = params.mode || 'horizontal';
this.modes = {horizontal:['left','width'], vertical:['top','height']};
this.size = params.size || 240;
this.box = params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
this.button_event = params.button_event || 'click';
this.handle_event = params.handle_event || 'click';
this.onWalk = params.onWalk || null;
this.currentIndex = null;
this.previousIndex = null;
this.nextIndex = null;
this.interval = params.interval || 5000;
this.duration = params.duration || 500;
this.autoPlay = params.autoPlay || false;
this._play = null;
this.handles = params.handles || null;
if(this.handles){
this.addHandleButtons(this.handles);
}
this.buttons = {
previous: [],
next: [],
play: [],
playback: [],
stop: []
};
if(params.addButtons){
for(var action in params.addButtons){
this.addActionButtons(action, $type(params.addButtons[action])=='array' ? params.addButtons[action] : [params.addButtons[action]]);
}
}
this.fx = new Fx.Tween(this.box,$extend((params.fxOptions||{duration:this.duration,wait:false}),{property:this.modes[this.mode][0]}));
this.walk((params.startItem||0),true,true);
},
addHandleButtons: function(handles){
for(var i=0;i<handles.length;i++){
handles[i].addEvent(this.handle_event,this.walk.bind(this,[i,true]));
}
},
addActionButtons: function(action,buttons){
for(var i=0; i<buttons.length; i++){
switch(action){
case 'previous': buttons[i].addEvent(this.button_event,this.previous.bind(this,[true])); break;
case 'next': buttons[i].addEvent(this.button_event,this.next.bind(this,[true])); break;
case 'play': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'next',false])); break;
case 'playback': buttons[i].addEvent(this.button_event,this.play.bind(this,[this.interval,'previous',false])); break;
case 'stop': buttons[i].addEvent(this.button_event,this.stop.bind(this)); break;
}
this.buttons[action].push(buttons[i]);
}
},
previous: function(manual){
this.walk((this.currentIndex>0 ? this.currentIndex-1 : this.items.length-1),manual);
},
next: function(manual){
this.walk((this.currentIndex<this.items.length-1 ? this.currentIndex+1 : 0),manual);
},
play: function(interval,direction,wait){
this.stop();
if(!wait){
this[direction](false);
}
this._play = this[direction].periodical(interval,this,[false]);
},
stop: function(){
$clear(this._play);
},
walk: function(item,manual,noFx){
if(item!=this.currentIndex){
this.currentIndex=item;
this.previousIndex = this.currentIndex + (this.currentIndex>0 ? -1 : this.items.length-1);
this.nextIndex = this.currentIndex + (this.currentIndex<this.items.length-1 ? 1 : 1-this.items.length);
if(manual){
this.stop();
}
if(noFx){
this.fx.cancel().set((this.size*-this.currentIndex)+'px');
}else{
this.fx.start(this.size*-this.currentIndex);
}
if(manual && this.autoPlay){
this.play(this.interval,'next',true);
}
if(this.onWalk){
this.onWalk((this.items[this.currentIndex] || null), (this.handles && this.handles[this.currentIndex] ? this.handles[this.currentIndex] : null));
}
}
}
});
/*
作者:
路易斯达15,
许可证:
麻省理工学院执照
班
noobSlide(版本19-06-08)
论据:
参数-请参见下面的参数
参数:
框:dom元素|必需
项目:dom集合|必需
大小:int |项目大小(px)|默认值:240
模式:字符串|“水平”、“垂直”|默认值:“水平”
添加按钮:{
上一个:单个dom元素或dom集合|默认值:null
下一步:单个dom元素或dom集合|默认值:null
播放:单个dom元素或dom集合|默认值:null
回放:单个dom元素或dom集合|默认值:null
停止:单个dom元素或dom集合|默认值:null
}
按钮|事件:字符串|事件类型|默认值:“单击”
句柄:dom集合|默认值:null
句柄|事件:字符串|事件类型|默认值:“单击”
fxOptions:object | Fx.Tween options |默认值:{duration:500,wait:false}
间隔:int |对于定期|默认值:5000
自动播放:布尔值|默认值:false
onWalk:event |传递参数:currentItem,currentHandle |默认值:null
startItem:int |默认值:0
特性:
框:dom元素
项目:dom集合
大小:int
模式:字符串
按钮:对象
按钮事件:字符串
句柄:dom集合
句柄事件:字符串
先前索引:int
nextIndex:int
fx:fx.Tween实例
间隔:int
自动播放:布尔值
onWalk:函数
方法:
上一个(手动):转到上一个项目
手动:bolean |默认值:false
下一步(手动):走到下一项
手动:bolean |默认值:false
播放(间隔、方向、等待):自动行走项目
间隔:int |必需
方向:字符串|“上一个”或“下一个”|必需
等待:布尔值|必需
停止():停止自动行走
步行(项目、手动、noFx):步行至项目
项目:int |必需
手动:bolean |默认值:false
noFx:boolean |默认值:false
添加把手按钮(把手):
句柄:dom集合|必需
添加操作按钮(操作,按钮):
操作:字符串|“上一个”、“下一个”、“播放”、“播放”、“停止”|必需
按钮:dom集合|必需
要求:
mootools 1.2核心
*/
var noobSlide=新类({
初始化:函数(参数){
this.items=params.items;
this.mode=params.mode | |“水平”;
this.modes={水平方向:['left','width'],垂直方向:['top','height']};
this.size=params.size | | 240;
this.box=params.box.setStyle(this.modes[this.mode][1],(this.size*this.items.length)+'px');
this.button_event=params.button_event | | |'单击';
this.handle|u event=params.handle|u event |“单击”;
this.onWalk=params.onWalk | | null;
this.currentIndex=null;
this.previousIndex=null;
this.nextIndex=null;
this.interval=params.interval | | 5000;
this.duration=params.duration | | 500;
this.autoPlay=params.autoPlay | | false;
这个。_play=null;
this.handles=params.handles | | null;
if(this.handles){
this.addHandleButtons(this.handles);
}
此按钮={
以前:[],
下一个:[],
播放:[],
播放:[],
停止:[]
};
if(参数添加按钮){
for(params.addButtons中的变量操作){
this.addActionButtons(action,$type(params.addButtons[action])=='array'?params.addButtons[action]:[params.addButtons[action]]);
}
}
this.fx=new fx.Tween(this.box,$extend((params.fxOptions | |{duration:this.duration,wait:false}),{property:this.modes[this.mode][0]});
这个行走((params.startItem | | 0),真的,真的);
},
addHandleButtons:函数(句柄){
对于(var i=0;i,您只需查看JavaScript方法的名称
next()
-> this.walk(...)
-> this.fx.start(...)
this.fx
属性来自:
this.fx = new Fx.Tween(...)
在initialize()
方法中。阅读