为什么on和triggerHandler后面可以加auto_move,move_next

来源:5-8 首页.UI组件-UiSlider(3)

慕村1222722

2019-08-14 10:16:37

wrap

.on('move_prev',function(){

if(current<=0){

current = size;

}

current = current - 1 ;

wrap.triggerHandler('move_to',current);

})

.on('move_next',function(){

if( current >= size-1){

current = -1;

}

current = current + 1 ;

wrap.triggerHandler('move_to',current);

})

.on('move_to',function(evt,index){

wrap.css('left',index*width*-1);

tips.removeClass('item_focus').eq(index).addClass('item_focus');

})

.on('auto_move',function(){


setInterval(function(){

enableAuto && wrap.triggerHandler('move_next');

},2000);


})

.triggerHandler('auto_move');


// 事件

btn_prev.on('click',function(){

wrap.triggerHandler('move_prev');

});

btn_next.on('click',function(){

wrap.triggerHandler('move_next');

});

tips.on('click',function(){

var index = $(this).index();

wrap.triggerHandler('move_to',index);

})


写回答

1回答

好帮手慕星星

2019-08-14

同学你好,

jquery中on是可以绑定自定义事件的,所以这里auto_move,move_next,auto_move这三个是自定义的事件名称。然后通过triggerHandler方法触发事件执行:

http://img.mukewang.com/climg/5d5389310001a71604180443.jpg

代码中通过元素的点击事件触发自定义事件执行。

自己可以测试理解下,祝学习愉快!

欢迎采纳~

0

0 学习 · 14456 问题

查看课程