Javascript cannot capture the mouse up event conjecture on the scroll bar

Source: Internet
Author: User

Address: http://www.cnblogs.com/lln7777/archive/2012/03/21/2409404.html

For example, in a webpage chat room, the scroll bar will automatically scroll down as the content increases.

When you press the mouse over the scroll bar, we can assume that he or she is browsing the chat content. In this case, a good user experience will not allow the scroll bar to automatically scroll.

To implement this function, you may first think of the mouse down and mouse up events.

However, we will find that the mouse up cannot be captured when the left mouse button is pressed on the scroll bar and then released. Example:

<Html>
<Head>
<Title> </title>
<Script type = "text/javascript">
Var captureTarget = null;

Function down (obj, e ){
CaptureTarget = obj;
// Open comments for IE
// CaptureTarget. setCapture ();
E = e? E: window. event;
}

Function up (obj, e ){
// If (captureTarget)
// CaptureTarget. releaseCapture ();
E = e? E: window. event;
Div2.innerText = e. srcElement. tagName;
}

Document. addListener = function (event, callback ){
If (! Document. all)
This. addEventListener (event, callback );
Else
This. attachEvent ("on" + event, callback );
}

Document. addListener ("mouseup", function () {alert (1 );});
</Script>
</Head>

<Body>
<Div style = "width: 200px; height: 200px; overflow: scroll" onmousedown = "down (this, event);">
<Div style = "height: 500px; width: 500px"> </div>
</Div>
</Body>

</Html>

Save it as an html file, open it in the browser, and click "try" on the scroll bar, and then click "try" elsewhere.

 

Since we have not studied W3C documents in depth, we can only guess here.

Considering the features of the scroll bar, the browser may have setCapture for the scroll bar when you press the scroll bar with the mouse, and releaseCapture for the scroll bar after the mouse is released. the scroll bar does not belong to the Dom object, therefore, the mouseup event cannot be captured before the mouse is released.

Pure conjecture. Welcome to the bricks.

Related Article

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.