scroll-view.js 705 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const order = ['blue', 'red', 'green', 'yellow'];
  2. Page({
  3. data: {
  4. toView: 'red',
  5. scrollTop: 100,
  6. },
  7. upper(e) {
  8. console.log(e);
  9. },
  10. lower(e) {
  11. console.log(e);
  12. },
  13. scroll(e) {
  14. console.log(e.detail.scrollTop);
  15. },
  16. scrollToTop(e) {
  17. console.log(e);
  18. this.setData({
  19. scrollTop: 0,
  20. });
  21. },
  22. tap(e) {
  23. for (let i = 0; i < order.length; ++i) {
  24. if (order[i] === this.data.toView) {
  25. const next = (i + 1) % order.length;
  26. this.setData({
  27. toView: order[next],
  28. scrollTop: next * 200,
  29. });
  30. break;
  31. }
  32. }
  33. },
  34. tapMove() {
  35. this.setData({
  36. scrollTop: this.data.scrollTop + 10,
  37. });
  38. },
  39. });