


二,关联List和Slider
List的一般基础设置:
this.con_list.itemRender = BallSkinRender;
this.con_list.array = null;
this.con_list.vScrollBarSkin = "";
this.con_list.scrollBar.elasticBackTime = 500;
this.con_list.scrollBar.elasticDistance = 200;
this.con_list.repeatX = 4;
this.con_list.spaceX = 10;
this.con_list.spaceY = 10;
this.con_list.scrollBar.isVertical = true;
this.con_list.scrollBar.setScroll( 0 , 100, 0 );
this.con_list.selectHandler = Laya.Handler.create(this , this._list_select , null , false);
this.con_list.scrollBar.changeHandler = Laya.Handler.create( this , this._scroll_Change , null , false );
注解 :
① : 设置 this.con_list.vScrollBarSkin = ""; 才能设置回弹 , 进度等信息 . 比如 :this.con_list.scrollBar.changeHandler = Laya.Handler.create( this , this._scroll_Change , null , false );
我们可以侦听到进度的信息.
② : this.con_list.scrollBar.setScroll( 0 , 100, 0 ); 参数 : 1 , 最小值 ; 2 , 最大值 ; 3 , 当前值
核心关联:
/**
* 选择元素
* @param {number} $index 从0开始
* @private
*/
private _list_select( $index : number ) : void{
console.log(`AAACCC : ${$index}`);
}
private _scroll_Change( $value : number ) : void{
if( $value <= 0 ){
this.vs_bar.value = 0;
}else if( $value >= this.con_list.scrollBar.max ){
this.vs_bar.value = 100;
}else{
this.vs_bar.value = ( ($value * 1.0) / this.con_list.scrollBar.max ) * 100;
}
}
注解 : ① : vs_bar 即 Slider
② : _scroll_Change方法实现了关联.(是Slider滑块位置准确反映List拖动的进度).
原文:http://blog.51cto.com/aonaufly/2312454