GlobalEventHandlers.onmouseup - Web APIs 编辑
The onmouseup
property of the GlobalEventHandlers
mixin is an EventHandler
that processes mouseup
events.
The mouseup
event fires when the user releases the mouse button.
Note: The opposite of onmouseup
is onmousedown
.
Syntax
target.onmouseup = functionRef;
Value
functionRef
is a function name or a function expression. The function receives a MouseEvent
object as its sole argument.
Example
In this example, a piece of "toast" hides when you click down with the mouse, and reappears when you release. It uses the onmousedown
and onmouseup
event handlers.
HTML
<div class="container">
<div class="toaster"></div>
<div class="toast">Hello world!</div>
</div>
CSS
.container {
position: absolute;
left: 50%;
bottom: 20px;
transform: translate(-50%);
}
.toaster {
width: 160px;
height: 110px;
background: #bbb;
border-radius: 10px 10px 0 0;
}
.toast {
position: absolute;
left: 50%;
top: 50%;
z-index: -1;
width: 100px;
height: 50px;
padding: 10px;
background: #ed9;
border-radius: 10px 10px 0 0;
transform: translate(-50%, -90px);
transition: transform .3s;
}
.depressed {
transform: translate(-50%, -50%);
}
JavaScript
function depress() {
toast.classList.add('depressed');
}
function release() {
toast.classList.remove('depressed');
}
const toaster = document.querySelector('.toaster');
const toast = document.querySelector('.toast');
toaster.onmousedown = depress;
document.onmouseup = release;
Result
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'onmouseup' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
See also
mouseup
event
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论