page-scroll.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. height:0,
  29. upper:true
  30. },
  31. ready:function(){
  32. },
  33. methods: {
  34. scrollLower:function(e){
  35. this.triggerEvent("scrolltolower",e.detail);
  36. },
  37. scrollUpper:function(e){
  38. this.triggerEvent("scrolltoupper",e.detail);
  39. },
  40. scroll:function(e){
  41. if(this.data.upper){
  42. if(e.detail.scrollTop>this.data["upper-threshold"]){
  43. this.setData({
  44. upper:false,
  45. height:0
  46. })
  47. }
  48. }else{
  49. if(e.detail.scrollTop<this.data["upper-threshold"]){
  50. this.setData({
  51. upper:true
  52. })
  53. }
  54. }
  55. this.triggerEvent("scroll",{scrollTop:e.detail.scrollTop,isuper:this.data.upper});
  56. },
  57. changeHeight:function(e){
  58. var _self=this;
  59. if(this.data.starttop){
  60. this.setData({
  61. height:(e.touches[0].pageY-this.data.starttop)/2
  62. })
  63. this.triggerEvent("topheight",this.data.height);
  64. }else{
  65. this.setData({
  66. starttop:e.touches[0].pageY
  67. })
  68. }
  69. },
  70. endChange:function(e){
  71. var obj = {
  72. starttop:0
  73. }
  74. if(this.data.height){
  75. obj.height=0;
  76. }
  77. this.setData(obj);
  78. this.triggerEvent("topheight",this.data.height);
  79. }
  80. }
  81. })