Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InteractiveLogo
- j_el = false
- top_offset = 0
- left_offset = 0
- constructor: () ->
- logo = this
- this.j_el = $('#logo')
- this.tl = document.getElementById('logo-topleft-line')
- this.tr = document.getElementById('logo-topright-line')
- this.bl = document.getElementById('logo-bottomleft-line')
- this.br = document.getElementById('logo-bottomright-line')
- this.logotype = document.getElementById('logotype')
- offset = this.j_el.offset()
- this.left_offset = offset.left
- this.top_offset = offset.top
- this.j_el.bind('mousein mousemove', (event)->
- logo.follow_mouse(event)
- )
- this.j_el.bind('mouseout', (event)->
- logo.reset_position()
- )
- reset_position: () ->
- this.tl.setAttribute('d','M 0,0 44,-34')
- this.tr.setAttribute('d','M 0,0 -44,-34')
- this.bl.setAttribute('d','M 0,0 -44,-34')
- this.br.setAttribute('d','M 0,0 44,-34')
- this.logotype.setAttribute('transform','translate(0,0)')
- follow_mouse: (move_event) ->
- horizontal_pos = move_event.pageX - this.left_offset - 110
- if horizontal_pos > 60
- horizontal_pos = 60
- else if horizontal_pos < -60
- horizontal_pos = -60
- page_y =- move_event.pageY
- vertical_pos = page_y - this.top_offset + 170
- if vertical_pos > 64
- vertical_pos = 64
- else if vertical_pos < -64
- vertical_pos = -64
- this.logotype.setAttribute('transform','translate(' + horizontal_pos + ',' + vertical_pos + ')')
- horizontal_percentage = ((horizontal_pos + 60) / 120) * 100
- vertical_percentage = ((vertical_pos + 64) / 160) * 100
- this.tl.setAttribute('d', 'M 0,0 ' + horizontal_percentage + ',' + (vertical_percentage - 80))
- this.tr.setAttribute('d', 'M 0,0 ' + (horizontal_percentage - 100) + ',' + (vertical_percentage - 80))
- this.bl.setAttribute('d', 'M ' + (horizontal_percentage - 44) + ',' + (vertical_percentage - 34) + ' -44,-34')
- this.br.setAttribute('d', 'M ' + (horizontal_percentage - 56) + ',' + (vertical_percentage - 34) + ' 44,-34')
- $(document).ready(
- # ::TODO:: only activate if SVG is supported and on non-touch devices
- interactive_logo = new InteractiveLogo()
- )
Add Comment
Please, Sign In to add comment