jquery - Making vertical list scroll on mouse over -


i have vertical list in navigation longer screens height. when start hover on list list start in move when mouse around half way down list.

any advice on appreciated.

thank in advance.

one approach, below:

var ul = $('ul:first'), ulheight = ul.outerheight(); ul.on('mousemove', function(e){ var win = $(window), cst = win.scrolltop(); if (e.pagey>=(ulheight/2)){ win.scrolltop(cst + 20); } else { win.scrolltop(cst - 20); } });​ 

js fiddle demo.

this based upon halfway point of list itself, , therefore relies on halfway point being visible on page itself.

to make more functional, ul within containing element, , scrolling based upon being past halfway point of containing element:

var div = $('#wrap'), wrapheight = div.height(), listheight = div.find('ul').outerheight(); div.on('mousemove', function(e){ var cpointy = e.pagey, cst = div.scrolltop(); if (cpointy >= (wrapheight/2)) { div.scrolltop(cst + 15); } else { div.scrolltop(cst - 15); } });​ 

js fiddle demo.


edited add further option scrolls list element or down depending on position of cursor within containing element:

var div = $('#wrap'), wrapscreenheight = div.height(), wrapheight = div.outerheight(), listheight = div.find('ul').outerheight(); div.on('mousemove', function(e) { var cpointy = e.pagey, dp = ((cpointy / wrapheight)); div.scrolltop((listheight * dp) - wrapscreenheight); }); 

js fiddle demo. ​ references:


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -