ruby on rails - javascript animate-ScrollTop works randomly -



ruby on rails - javascript animate-ScrollTop works randomly -

i have list 10 elements after 5 seconds elements begin highlighted 1 after other , previous beingness unhighlighted. when highlighing reaches lastly element starts begining. highlighting beingness done adding selected id element. done until point.

there 3 elements visible in list rest of them needs scrolled to. getting tricky. have used:

scrolltoselected: => nav = $("#selected") if nav.length $(@el).animate scrolltop: nav.offset().top , 1000

this script doing scrolling not expected, scrolls randomly , downwards didn't knew tops of items. can problem be?

i have tried outputting .offset().top values in console result this:

171 -627 731 -19 1131 -891 419 -299 1011 101 -891 419 -299 1011 101 -891 419 -299 1011 101 -891 419 -299 1011 101 -891 419 -299 1011 101 -891 419 -299 196.5 248.5 492.5 512.5 612.5 -414.5

any thougths?

edit: after changing offset position these values: these 1 not wild still,it doesn't scroll expected, after 3-4th element selected 1 somewhere bellow visible ones

10 164 174 328 322 476 486 624 634 772 798 936 950 1100 1098 -1088

as mentioned in comments need utilize .position() instead of .offset() teh relative offset instead of document offset.

as order dropping after few elements sounds need increment scrolltop() , not replace it. give (untested) code go:

scrolltoselected: => nav = $("#selected") if nav.length el = $(@el) el.animate scrolltop: el.scrolltop() + nav.position().top , 1000

javascript ruby-on-rails backbone.js coffeescript

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -