Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript iPhone Scroll Effect in an iFrame / Javascript Mouse Acceleration
    primarykey
    data
    text
    <p>I'm trying to recreate the iPhone flick / scroll event in a window using JavaScript.</p> <p>Starting with JQuery, I'm measuring the mouse's acceleration and offset during click - drag - release events using a timer:</p> <pre><code>var MouseY = { init: function(context) { var self = this; self._context = context || window self._down = false; self._now = 0; self._last = 0; self._offset = 0; self._timer = 0; self._acceleration = 0; $(self._context).mousedown(function() {self._down = true;}); $(self._context).mouseup(function() {self._down = false;}); $(self._context).mousemove(function(e) {self.move(e);}); }, move: function(e) { var self = this; self._timer++; self._last = self._now; self._now = e.clientY + window.document.body.scrollTop; self._offset = self._now - self._last; self._acceleration = self._offset / self._timer; }, reset: function() { this._offset = 0; this._acceleration = 0; this._timer = 0; } }; $(function() { MouseY.init(); setInterval(function() { $('#info').html( '_acceleration:' + MouseY._acceleration + '&lt;br /&gt;' + '_now:' + MouseY._now + '&lt;br /&gt;' + '_offset:' + MouseY._offset + '&lt;br /&gt;' + '_timer:' + MouseY._timer + '&lt;br /&gt;' ); MouseY.reset(); }, 10); }); </code></pre> <p>Now the problem is translating that acceleration into screen movement - are there any algorithms (easing?) or animation libraries that could help me out on this? (I've looked into JQuery's .animate() but I'm unsure of how to apply it continuously during the drag events!</p> <p><strong>Update - final solution here:</strong></p> <p><a href="http://johnboxall.github.com/iphone.html" rel="noreferrer">http://johnboxall.github.com/iphone.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload