JS cannot capture the reason for the mouse up event on the scroll bar guess _javascript tips

Source: Internet
Author: User
For example, a web chat room, the scroll bar will automatically scroll down as the content increases.
When the user clicks on the scroll bar, we can assume that he or she is browsing the chat content, then the good user experience will not allow the scroll bar to automatically scroll again.
In order to achieve this function, perhaps the first thing you will think of is the mouse down and mouse up events.
But the concrete implementation of the time we will find in the scroll bar to press the left mouse button and then loosen, capture mouse up. As shown in the following example
Copy Code code as follows:

<title></title>
<script type= "Text/javascript" >
var capturetarget = null;
function down (obj, e) {
Capturetarget = obj;
If IE can open a comment
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>
<body >
<div style= "Width:200px;height:200px;overflow:scroll" onmousedown= "Down (this, event);" >
<div style= "height:500px; width:500px "></div>
</div>
</body>

Save as HTML format file, browser Open, and then left-click on the scroll bar to try, and then click on another place to try.
Since there is no in-depth study of the documents of the consortium, there is only conjecture.
Considering the characteristics of the scroll bar, it is possible that the browser setcapture the scroll bar when the mouse presses the scroll bar, and then gives the mouse a releasecapture when it is released, and the scroll bar does not belong to the DOM object, so the MouseUp event cannot be captured before the mouse is released.

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.