123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- // components/page-scroll/page-scroll.js
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- "className":{
- value:"",
- type:String
- },
- "styleSheet":{
- value:"",
- type:String
- },
- "upper-threshold":{
- value:5,
- type:Number
- },
- "scrollitem":{
- value:[],
- type:Array
- },
- "scrollto":{
- value:"",
- type:Number
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- height:0,
- upper:true,
- index:0
- },
- ready:function(){
- },
- methods: {
- scrollLower:function(e){
- this.triggerEvent("scrolltolower",e.detail);
- },
- scrollUpper:function(e){
- this.triggerEvent("scrolltoupper",e.detail);
- },
- scroll:function(e){
- var scrolltop = e.detail.scrollTop;
- var scrollitem =this.data.scrollitem;
- var index = 0;
- if(this.data.upper){
- if(scrolltop>this.data["upper-threshold"]){
- this.setData({
- upper:false,
- height:0
- })
- }
- }else{
- if(scrolltop<this.data["upper-threshold"]){
- this.setData({
- upper:true
- })
- }
- }
- var l = scrollitem.length;
- if(scrolltop>scrollitem[l-1]){
- index=l;
- }else{
- for(var i=0;i<l;i++){
- if(scrolltop<scrollitem[i]){
- index = i;
- break;
- }
- }
- }
- if(index!=this.data.index){
- this.setData({
- index:index
- });
- this.triggerEvent("swc",index);
- }
- this.triggerEvent("scroll",this.data.upper);
- },
- changeHeight:function(e){
- var _self=this;
- if(this.data.starttop){
- this.setData({
- height:(e.touches[0].pageY-this.data.starttop)/2
- })
- this.triggerEvent("topheight",this.data.height);
- }else{
- this.setData({
- starttop:e.touches[0].pageY
- })
- }
- },
- endChange:function(e){
- var obj = {
- starttop:0
- }
- if(this.data.height){
- obj.height=0;
- }
- this.setData(obj);
- this.triggerEvent("topheight",this.data.height);
- }
- }
- })
|