page-scroll.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // components/page-scroll/page-scroll.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. "className":{
  8. value:"",
  9. type:String
  10. },
  11. "styleSheet":{
  12. value:"",
  13. type:String
  14. },
  15. "upper-threshold":{
  16. value:5,
  17. type:Number
  18. },
  19. "scroll-into-view":{
  20. value:"",
  21. type:String
  22. },
  23. "bgcolor":{
  24. value:"",
  25. type:String
  26. }
  27. },
  28. /**
  29. * 组件的初始数据
  30. */
  31. data: {
  32. height:0,
  33. upper:true
  34. },
  35. ready:function(){
  36. },
  37. methods: {
  38. scrollLower:function(e){
  39. this.triggerEvent("scrolltolower",e.detail);
  40. },
  41. scrollUpper:function(e){
  42. this.triggerEvent("scrolltoupper",e.detail);
  43. },
  44. scroll:function(e){
  45. if(this.data.upper){
  46. if(e.detail.scrollTop>this.data["upper-threshold"]){
  47. this.setData({
  48. upper:false,
  49. height:0
  50. })
  51. }
  52. }else{
  53. if(e.detail.scrollTop<this.data["upper-threshold"]){
  54. this.setData({
  55. upper:true
  56. })
  57. }
  58. }
  59. this.triggerEvent("scroll",{scrollTop:e.detail.scrollTop,isuper:this.data.upper});
  60. },
  61. changeHeight:function(e){
  62. var _self=this;
  63. if(this.data.starttop){
  64. this.setData({
  65. height:(e.touches[0].pageY-this.data.starttop)/2
  66. })
  67. this.triggerEvent("topheight",this.data.height);
  68. }else{
  69. this.setData({
  70. starttop:e.touches[0].pageY
  71. })
  72. }
  73. },
  74. endChange:function(e){
  75. var obj = {
  76. starttop:0
  77. }
  78. if(this.data.height){
  79. obj.height=0;
  80. }
  81. this.setData(obj);
  82. this.triggerEvent("topheight",this.data.height);
  83. }
  84. }
  85. })