topsource.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const scrollevents = {
  2. sourceUp:function(e){
  3. var obj = {
  4. scrolltop:0,
  5. distance:0,
  6. startdot:""
  7. }
  8. this.setData({
  9. scrollsource:Object.assign(this.data.scrollsource,obj)
  10. })
  11. },
  12. sourceScroll:function(e){
  13. var scrolltop = e.detail.scrollTop;
  14. var obj = {scrolltop:scrolltop};
  15. if(scrolltop&&this.data.scrollsource.startdot){
  16. obj.startdot = "";
  17. obj.distance = 0;
  18. obj.scrolltop = 0
  19. this.setData({
  20. scrollsource:Object.assign(this.data.scrollsource,obj)
  21. })
  22. }else{
  23. this.setData({
  24. scrollsource:Object.assign(this.data.scrollsource,{
  25. scrolltop:scrolltop
  26. })
  27. })
  28. }
  29. },
  30. sourceMove:function(e){
  31. var source = this.data.scrollsource
  32. if(e.timeStamp-source.timeStamp>200){
  33. if(source.startdot){
  34. var startdot = source.startdot;
  35. var enddot = e.changedTouches[0];
  36. var distance = enddot.pageY-startdot.pageY;
  37. this.setData({
  38. scrollsource:Object.assign(source,{distance:distance})
  39. })
  40. }else if(!source.scrolltop){
  41. var startdot = e.changedTouches[0];
  42. this.setData({
  43. scrollsource:Object.assign(source,{
  44. startdot:startdot,
  45. timeStamp:e.timeStamp
  46. }),
  47. })
  48. }
  49. }
  50. //console.log("consoleMove",e)
  51. },
  52. sourceStart:function(e){
  53. //console.log("sourceStart",e)
  54. var startdot = e.changedTouches[0];
  55. this.setData({
  56. scrollsource:Object.assign(this.data.scrollsource,{
  57. startdot:startdot,
  58. timeStamp:e.timeStamp
  59. })
  60. });
  61. },
  62. sourceEnd:function(e){
  63. this.setData({
  64. scrollsource:Object.assign(this.data.scrollsource,{
  65. distance:0,
  66. startdot:""
  67. })
  68. })
  69. //console.log("consoleEnd",e)
  70. }
  71. }
  72. export default function(item){
  73. item.setData({
  74. scrollsource:{
  75. scrolltop:0
  76. }
  77. })
  78. Object.assign(item,scrollevents);
  79. }