EFMarquee.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. class EFMarquee {
  2. constructor() {
  3. this.element = null;
  4. }
  5. static getInstance() {
  6. return (typeof yunos != 'undefined') ? tv_marquee : new EFMarquee();
  7. }
  8. create(node, speed) {
  9. this.element = node;
  10. this.timer = null;
  11. this.startX = 0;
  12. this.stopX = 0;
  13. this.currentX = 0;
  14. return this;
  15. }
  16. start(circle) {
  17. // this.element.className = 'ef_marquee';
  18. this.element.classList.add('ef_marquee');
  19. console.log('document :' + document.body.clientWidth);
  20. console.log('marquee p width:' + this.element.childNodes[0].clientWidth);
  21. this.startX = this.element.clientWidth;
  22. this.stopX = this.element.childNodes[0].clientWidth * -1;
  23. this.currentX = this.startX;
  24. function updateFrame(dom, x) {
  25. dom.setAttribute('style', 'left:' + x + 'px');
  26. }
  27. function update(context) {
  28. context.timer = setTimeout(function() {
  29. context.currentX -= 1;
  30. updateFrame(context.element.childNodes[0], context.currentX);
  31. if (context.currentX > context.stopX) {
  32. update(context);
  33. return;
  34. }
  35. if (circle) {
  36. context.currentX = context.startX;
  37. update(context);
  38. } else {
  39. context.currentX = 0;
  40. updateFrame(context.element.childNodes[0], context.currentX);
  41. }
  42. }.bind(this), 30);
  43. }
  44. update(this);
  45. }
  46. setStr(str) {
  47. this.element.innerHTML = '<p>' + str + '</p>';
  48. }
  49. stop() {
  50. this.element.className = '';
  51. clearTimeout(this.timer);
  52. }
  53. }
  54. module.exports = EFMarquee;