Guest User

Untitled

a guest
Dec 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. class InteractiveLogo
  2. j_el = false
  3. top_offset = 0
  4. left_offset = 0
  5. constructor: () ->
  6. logo = this
  7. this.j_el = $('#logo')
  8. this.tl = document.getElementById('logo-topleft-line')
  9. this.tr = document.getElementById('logo-topright-line')
  10. this.bl = document.getElementById('logo-bottomleft-line')
  11. this.br = document.getElementById('logo-bottomright-line')
  12. this.logotype = document.getElementById('logotype')
  13. offset = this.j_el.offset()
  14. this.left_offset = offset.left
  15. this.top_offset = offset.top
  16. this.j_el.bind('mousein mousemove', (event)->
  17. logo.follow_mouse(event)
  18. )
  19. this.j_el.bind('mouseout', (event)->
  20. logo.reset_position()
  21. )
  22. reset_position: () ->
  23. this.tl.setAttribute('d','M 0,0 44,-34')
  24. this.tr.setAttribute('d','M 0,0 -44,-34')
  25. this.bl.setAttribute('d','M 0,0 -44,-34')
  26. this.br.setAttribute('d','M 0,0 44,-34')
  27. this.logotype.setAttribute('transform','translate(0,0)')
  28. follow_mouse: (move_event) ->
  29. horizontal_pos = move_event.pageX - this.left_offset - 110
  30. if horizontal_pos > 60
  31. horizontal_pos = 60
  32. else if horizontal_pos < -60
  33. horizontal_pos = -60
  34. page_y =- move_event.pageY
  35. vertical_pos = page_y - this.top_offset + 170
  36. if vertical_pos > 64
  37. vertical_pos = 64
  38. else if vertical_pos < -64
  39. vertical_pos = -64
  40.  
  41. this.logotype.setAttribute('transform','translate(' + horizontal_pos + ',' + vertical_pos + ')')
  42.  
  43. horizontal_percentage = ((horizontal_pos + 60) / 120) * 100
  44. vertical_percentage = ((vertical_pos + 64) / 160) * 100
  45.  
  46. this.tl.setAttribute('d', 'M 0,0 ' + horizontal_percentage + ',' + (vertical_percentage - 80))
  47. this.tr.setAttribute('d', 'M 0,0 ' + (horizontal_percentage - 100) + ',' + (vertical_percentage - 80))
  48. this.bl.setAttribute('d', 'M ' + (horizontal_percentage - 44) + ',' + (vertical_percentage - 34) + ' -44,-34')
  49. this.br.setAttribute('d', 'M ' + (horizontal_percentage - 56) + ',' + (vertical_percentage - 34) + ' 44,-34')
  50.  
  51.  
  52. $(document).ready(
  53. # ::TODO:: only activate if SVG is supported and on non-touch devices
  54. interactive_logo = new InteractiveLogo()
  55. )
Add Comment
Please, Sign In to add comment