javascript - jquery scroller mousewheel with keyboard -
i have site scroller here article trying add keyboard keys , down below code
[http://jsfiddle.net/roxon/r3x7r/1/]
control page scroll animation mousewheel
kindly 1 let me know if possible..
hope you,
added keyboard shortcut scrolling in page sections.
// our code var winh = $(window).height(); $('.page').height(winh); var c = 0; var pagesn = $('.page').length; var activepage=0; $(document).bind('mousewheel', function(ev, delta) { delta>0 ? --c : ++c ; if(c===-1){ c=0; }else if(c===pagesn){ c=pagesn-1; } activepage = c; var pagepos = $('.page').eq(c).position().top; $('html, body').stop().animate({scrolltop: pagepos},{easing: 'easeincirc', duration: 1200}); return false; }); $(document).bind('keyup', function(event){ console.log(event); if(event.which == 40) { activepage = activepage+1; var pagepos = $('.page').eq(activepage).position().top; $('html, body').stop().animate({scrolltop: pagepos},{easing: 'easeincirc', duration: 1200}); } else if(event.which == 38) { activepage = activepage-1; var pagepos = $('.page').eq(activepage).position().top; $('html, body').stop().animate({scrolltop: pagepos},{easing: 'easeincirc', duration: 1200}); } return false; });
Comments
Post a Comment