How to control the scroll increment in Firefox when clicking the scrollbar buttons?
I thought it开发者_高级运维 was related to line-height CSS property, but it doesn't work. How to adjust the scroll amount when clicking the scroll up/down buttons?
As far as I know, this isn't something you have control over. However, you could listen for the Javascript onScroll event and then use the Javascript scrollBy method to scroll the page more or less depending on what you wanted. I'm not sure how this would look though, things could be a bit jerky and confusing to the user. You'd also have to take into account whether or not the user has zoomed the page in or out.
Assuming you want to scroll an arbitrary area (rather than an object, such as a tree, that already supports scrolling), then you could set overflow: hidden and use explicit scrollbar elements. Unfortunately there's no easy way for script to detect user interaction with scrollbar elements, other than watching the curpos attribute.
You can't control, directly, the scroll increment in Firefox when clicking the scrollbar buttons but you can use this code:
//element may be window or a HTML element
//amount of incrementation should be an integer representing the number of pixels to be scrolled
//works in all last versions of major browsers
element.addEventListener(/firefox/i.test(navigator.userAgent) ? 'DOMMouseScroll' : 'mousewheel', function (event) {
element.scrollTop -= (event.detail ? (event.detail % 2 ? event.detail / -3 : event.detail / -2) : event.wheelDelta / 120) * amount;
event.preventDefault();
}
精彩评论