-->

JQuery Scroll and collect value of middle element

2019-08-23 14:51发布

问题:

I have set up 2 Fiddles. One is working perfectly. It is supposed to work out the middle value visible on screen.

The first fiddle performs this admirably on scroll.

The second incorporates a touch framework that does not work on scroll, but does work when you press the test button after scroll. This works on Google Chrome and Safari, but try it on Firefox. You will see it will not generate the correct value and stick at the bottom.

  • Working example :: http://jsfiddle.net/H3rHL/
  • Disfunctional :: http://jsfiddle.net/U4qyp/75/

Any ideas how to fix this.

Marvellous

回答1:

Try changing

$('#leftwheel').scroll(...);

to

$('#leftwheel').mousemove(...);

This won't be super-efficient, but will work OK for non-touch devices. See updated Fiddle

If you are looking to use this on touch devices, mousemove likely will not fire.