Although not Ruby, Coffeescript is part of every Rails developer’s toolkit now, and with front-end development comes the responsibility of responsive design. Today we look at how to grab a moving finger on a mobile device. In part two we will look at how to test the direction of a moving finger.

# app/assets/javascripts/touch_handler.js.coffee
 
movement =
  element: $('body')
  startingPointX: 0
  startingPointY: 0
 
movement.touching = (e) ->  
  e = e.originalEvent
  point = if e.touches then e.touches[0] else e
  movement.startingPointX = point.pageX
  movement.startingPointY = point.pageY
  console.log movement.startingPointX
  console.log movement.startingPointy
 
movement.element.bind 'touchmove', movement.touching

Leave a Reply

Your email address will not be published. Required fields are marked *