1. It is determined that the background color is changed to blue
2 when the event is away from the top 100px. Mousedown/up/move failure in chrome mobile mode
<template>
<div id="box">
<strong>:</strong><span></span>
<strong>:</strong><span></span>
</div>
</template>
<script>
export default {
mounted(){
window.onload = function() {
var oBox = document.getElementById("box");
var aSpan = oBox.getElementsByTagName("span");
var disY = 0;
var bDrag = false;
var aPos = [{
y: oBox.offsetTop
}]
//,
oBox.onmousedown = function(event) {
var event = event || window.event;
bDrag = true;
disY = event.clientY - oBox.offsetTop;
this.setCapture && this.setCapture();
return false
};
//
document.onmousemove = function(event) {
if(!bDrag) return;
var event = event || window.event;
var iT = event.clientY - disY;
var maxT = document.documentElement.clientHeight - oBox.offsetHeight;
iT = iT < 0 ? 0 : iT;
iT = iT > maxT ? maxT : iT;
oBox.style.marginTop = oBox.style.marginLeft = 0;
oBox.style.top = iT + "px";
aPos.push({
y: iT
})
status();
return false
};
//,
document.onmouseup = window.onblur = oBox.onlosecapture = function() {
bDrag = false;
oBox.releaseCapture && oBox.releaseCapture();
status()
};
//
function status() {
aSpan[0].innerHTML = bDrag;
aSpan[1].innerHTML = oBox.offsetTop;
}
//
status()}
}
}
</script>
<style>
html,body{
overflow: hidden;
}
body,div,p{
margin: 0;
padding: 0;
}
body {
font: 12px/2 Arial;
}
p {
padding: 0 10px;
margin-top: 10px;
}
span {
padding-left: 5px;
}
-sharpbox {
position: absolute;
width: 150px;
height: 150px;
border: 2px solid -sharpccc;
top: 0%;
left: 0%;
}
</style>