Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PlayerView
`import Ember from 'ember'`
PlayerView = Ember.View.extend(
offsetY: 140
mouseWheelFactor: 10
playerScroller: null
minY: 0
didInsertElement: ->
@setupPlayerScroller()
@initController()
@get('controller').on('addedPlayerItem', @, @addedPlayerItemHandler)
$(document).on('mousewheel', (event) => @mouseWheelHandler(event))
addedPlayerItemHandler: ->
Ember.run.next(@, ->
visibleHeight = $(window).height() - @offsetY
playerHeight = $('#player-content').height()
return if playerHeight < visibleHeight
@minY = visibleHeight - playerHeight
@playerScroller.spring()
.velocity(0, 0)
.to(0, @minY).start()
)
mouseWheelHandler: (event) ->
delta = event.originalEvent.wheelDelta / @mouseWheelFactor
interaction = @playerScroller.interact()
interaction.start()
prevY = @playerScroller.position().y
newY = prevY + delta
newY = 0 if newY > 0
newY = @minY if newY < @minY
interaction.position(0, newY)
false
setupPlayerScroller: ->
@playerScroller = Impulse($('#player-content')).style('translate', (x, y) -> "#{x}px, #{y}px")
initController: ->
@get('controller').onViewInsert()
)
`export default PlayerView`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment