index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // ui/marquee/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. text: {
  8. type: String,
  9. value: 'ILoveEwei'
  10. }
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. marqueePace: 5, //滚动速度
  17. marqueeDistance: 0, //初始滚动距离
  18. size: 14,
  19. orientation: 'left', //滚动方向
  20. interval: 50, // 时间间隔
  21. },
  22. /**
  23. * 组件的方法列表
  24. */
  25. methods: {
  26. _scrolling: function() {
  27. var _this = this;
  28. var timer = setInterval(() => {
  29. if (-_this.data.marqueeDistance < _this.data.length) {
  30. _this.setData({
  31. marqueeDistance: _this.data.marqueeDistance - _this.data.marqueePace
  32. })
  33. } else {
  34. clearInterval(timer);
  35. _this.setData({
  36. marqueeDistance: _this.data.windowWidth
  37. });
  38. _this._scrolling();
  39. }
  40. }, _this.data.interval);
  41. }
  42. },
  43. created: function() {
  44. var _this = this;
  45. var length = _this.data.text.length * _this.data.size;
  46. var windowWidth = wx.getSystemInfoSync().windowWidth
  47. _this.setData({
  48. length: length,
  49. windowWidth: windowWidth
  50. });
  51. _this._scrolling();
  52. }
  53. })