Mousewheel and DOMMouseScroll, dommousescroll
FF uses DOMMouseScroll, while other browsers use mousewheel.
FF has a special attribute event. detail, which indicates the rolling value.
Event. detail positive number: Scroll down, negative number: Scroll up once value 3, scroll up one page value is-32768, scroll down one page value is + 32768, other values represent the number of rows to scroll, A trusted event with positive and negative numbers in the direction does not assign 0 to detail.
In other browsers, use event. wheelDelta to obtain the positive value of the scroll value: Scroll up, negative number: Scroll down, and scroll down for a value of 120
// Non-FF
//event.wheelDelta
// Positive: Scroll up, negative: Scroll down
// Scroll for a value of 120
document.body.onmousewheel = function (event) {
event = event || window.event;
log('onmousewheel');
log(event);
log('event.detail=' + event.detail);//0
log('event.wheelDelta=' + event.wheelDelta);
};
//FF
// event.detail
// Positive: Scroll down, negative: Scroll up
// Scroll up a page with a value of-32768 and scroll down a page with a value of + 32768. Other values indicate the number of rows to scroll down and the direction indicates the positive and negative numbers of values.
// Trusted events do not assign 0 values to detail
document.body.addEventListener("DOMMouseScroll", function (event) {
log('DOMMouseScroll');
log(event);
log(event.detail);
});
function log(arg) {
window.console && window.console.log(arg);
}
Reference https://developer.mozilla.org/en-US/docs/Web/Events/DOMMouseScrollhttps://developer.mozilla.org/en-US/docs/Web/Events/mousewheel
Scroll wheel event in jQ
JQuery does not directly support mouse wheel events. There is a plug-in called jQuery Mousewheel. You can Google it.
However, it can be easily implemented using native JavaScript.
<Script type = "text/javascript"> // function executed after the scroll of the mouse pulley // delta> 0 = scroll up // delta <0 = scroll down function mousewheelEvent (e, delta) {document. getElementById ("debug "). innerHTML + = (delta + "<br/>"); // other code ...} if (document. attachEvent) {document. attachEvent ("onmousewheel", function (e) {mousewheelEvent (e, e. wheelDelta) ;}) ;}else if (document. addEventListener) {document. addEventListener ("DOMMouseScroll", function (e) {mousewheelEvent (e, e. detail *-40) ;}, false) ;}</script>
<Body style = "height: 3000px"> <div id = "debug" style = "position: fixed"> </div>
Hello, I have seen your question about the scroll bar. I am also facing this problem. I want to use my own picture as the scroll bar.
There are a lot of code that can't be sent. The idea is actually very simple, but debugging in terms of compatibility will be troublesome.
The following is the key code (JQuery is used)
Function addScrollBar (targetID, step_height, posType ){
Var mousewheel = $. browser. mozilla? "DOMMouseScroll": "mousewheel ";
Var targetObj = document. getElementById (targetID); // target object
If (! TargetObj ){
Return false;
}
TargetObj. style. overflow = 'ddd ';
Var targetObj_H = targetObj. offsetHeight; // object height
Var contentObj = targetObj. firstChild; // Content Object
Var contentObj_H = contentObj. offsetHeight; // height of the Content Object
If (targetObj_H> = contentObj_H) {// checks whether a scroll bar exists. Otherwise, the system returns
If (targetObj. lastChild. className = 'move _ bar '){
// TargetObj. lastChild. parentNode. removeChild (targetObj. lastChild );
// RemoveEvent (targetObj, mousewheel, move_scroll_bar, false );
// RemoveEvent (targetObj, 'mouseover', move_scroll_bar, false );
TargetObj. removeChild (targetObj. lastChild );
Return false;
} Else {
Return false;
}
}; ...... The remaining full text>