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.