jquery - CSS restrict overflow: scroll to selected element -
jquery - CSS restrict overflow: scroll to selected element -
i'm not sure if browser issue in webkit browsers, have div next css:
.fixed_box { position: fixed; top: 100px; height: 200px; width: 200px; overflow-y: scroll; } when scroll within div , nail top of div, rest of page starts scroll if there overflowing elements, haven't scrolled there.
i need set .fixed_box scroll when mouse within , scrolling.
thanks
you can utilize mousewheel , dommousescroll function accomplish this. add together next jquery in code.
$('.fixed_box').on('mousewheel dommousescroll', function(e) { var scrollto = null; if (e.type == 'mousewheel') { scrollto = (e.originalevent.wheeldelta * -1); } else if (e.type == 'dommousescroll') { scrollto = 40 * e.originalevent.detail; } if (scrollto) { e.preventdefault(); $(this).scrolltop(scrollto + $(this).scrolltop()); } }); explanation:
here have used 2 type of function because in jquery 1.7+, detail property not available @ jquery event object. so, need utilize event.originalevent.detail property @ dommousescroll event. method backwards-compatible older jquery versions.
coming within part, getting values of mousewheel height, means when utilize mouse or downwards how much height should go , downwards of particular div. using preventdafault function execute time default action of event not triggered. manually moving scroll , downwards using bottom line calculation.
the if status checking whether getting value or not using mousewheel function. if not getting values, "null" value. bottom preventdefault , positioning won't work.
have fiddle!!
jquery html css
Comments
Post a Comment