Mousewheel and DOMMouseScroll, dommousescroll

Source: Internet
Author: User

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

 
 
  1. // Non-FF
  2. //event.wheelDelta
  3. // Positive: Scroll up, negative: Scroll down
  4. // Scroll for a value of 120
  5. document.body.onmousewheel = function (event) {
  6. event = event || window.event;
  7. log('onmousewheel');
  8. log(event);
  9. log('event.detail=' + event.detail);//0
  10. log('event.wheelDelta=' + event.wheelDelta);
  11. };
  12. //FF
  13. // event.detail
  14. // Positive: Scroll down, negative: Scroll up
  15. // 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.
  16. // Trusted events do not assign 0 values to detail
  17. document.body.addEventListener("DOMMouseScroll", function (event) {
  18. log('DOMMouseScroll');
  19. log(event);
  20. log(event.detail);
  21. });
  22. function log(arg) {
  23. window.console && window.console.log(arg);
  24. }

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.