Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. (() => {
  2. class Core {
  3. constructor(animateEls) {
  4. this.animateEls = animateEls
  5.  
  6. this.animateFromTo
  7. this.animateTo
  8. };
  9.  
  10. returnAnimation() {
  11. return this.animateFromTo || this.animateTo
  12. };
  13.  
  14. };
  15.  
  16. class Animations extends Core {
  17. constructor(animateEls, time, from, to) {
  18. super(animateEls)
  19. this.time = time
  20. this.from = from
  21. this.to = to
  22. };
  23.  
  24. animateFromTo(options) {
  25. this.repeat = options.repeat
  26. this.animateFromTo = TweenMax.fromTo(this.animateEls, this.time, this.from, this.to).repeat(this.repeat)
  27. };
  28.  
  29. animateTo(options) {
  30. this.repeat = options.repeat
  31. this.animateTo = TweenMax.to(this.animateEls, this.time, this.to).repeat(this.repeat)
  32. };
  33.  
  34. killFromTo() {
  35. this.animateFromTo.kill()
  36. };
  37.  
  38. playFromTo() {
  39. this.animateFromTo.play()
  40. };
  41.  
  42. killTo() {
  43. this.animateTo.kill()
  44. };
  45.  
  46. playTo() {
  47. this.animateTo.play()
  48. };
  49.  
  50. };
  51.  
  52. class DetectOffscreen {
  53. constructor(root, core) {
  54. this.root = root
  55. this.core = core
  56.  
  57. window.addEventListener('load', () => this.killOffscreen(this.root, this.core))
  58. this.observeStyleChange()
  59. };
  60.  
  61. killOffscreen(root, core) {
  62. root.forEach(el => {
  63. this.top = el.getBoundingClientRect().top
  64.  
  65. if (this.top !== 0) {
  66. core.returnAnimation().kill()
  67. } else {
  68. core.returnAnimation().play()
  69. }
  70. })
  71. };
  72.  
  73. observeStyleChange() {
  74. this.target = document.querySelector('#pageable')
  75.  
  76. this.observer = new MutationObserver(mutations => {
  77. mutations.forEach(mutationRecord => {
  78. this.killOffscreen(this.root, this.core)
  79. });
  80. });
  81.  
  82. this.observer.observe(this.target, {
  83. attributes: true,
  84. attributeFilter: ['style']
  85. })
  86. };
  87.  
  88. };
  89.  
  90. //
  91. (() => {
  92. const height = document.querySelector('.aniamtions__lightbulbs-container').offsetHeight
  93. const from = {
  94. y: -height / 2,
  95. ease: Power0.easeNone
  96. }
  97. const to = {
  98. y: 0,
  99. ease: Power0.easeNone
  100. }
  101.  
  102.  
  103. const elementsAnimate = document.querySelectorAll('.aniamtions__lightbulbs-container');
  104. const root1 = document.querySelectorAll('.agency--first')
  105. const root2 = document.querySelectorAll('.agency--second')
  106.  
  107.  
  108.  
  109. const cube1 = new Animations(elementsAnimate[0], 4.5, from, to)
  110. cube1.animateFromTo({ repeat: -1 })
  111. const cube2 = new Animations(elementsAnimate[1], 4.5, from, to)
  112. cube2.animateFromTo({ repeat: -1 })
  113. //
  114. const detectOffScreen1 = new DetectOffscreen(root1, cube1)
  115. const detectOffScreen2 = new DetectOffscreen(root2, cube2)
  116.  
  117.  
  118. // const observer = new MutationObserver(mutations => {
  119. // mutations.forEach(mutationRecord => {
  120. // const detectOffScreen1 = new DetectOffscreen(root1, cube1)
  121. // const detectOffScreen2 = new DetectOffscreen(root2, cube2)
  122. // });
  123. // });
  124. //
  125. // const target = document.querySelector('#pageable')
  126. // observer.observe(target, { attributes: true, attributeFilter: ['style']
  127. })();
  128. // (() => {
  129. // const to = {
  130. // rotation: 360,
  131. // transformOrigin: 'center center',
  132. // ease: Power0.easeNone
  133. // }
  134. // const elements = []
  135. // const svgG = []
  136. // const svgElements = [...document.querySelectorAll('#_1915972218608')]
  137. //
  138. // for (const el of svgElements) {
  139. // elements.push(...el.children)
  140. // }
  141. // elements.forEach(el => svgG.push(...el.children))
  142. //
  143. //
  144. // const rotateAnimation = new Animations(svgG, 2, null, to)
  145. // rotateAnimation.animateTo({ repeat: -1 })
  146. // })();
  147. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement