<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
.g-wrap {
position: relative;
width: 120px;
height: 120px;
}
.g-box {
width: 120px;
height: 120px;
background: #000;
transform: translate(120px, 120px);
transition: 9999s 9999s;
}
.g-flag {
position: absolute;
width: 0;
height: 0;
top: -120px;
left: -120px;
display: inline-block;
line-height: 120px;
}
.g-wrap:active .g-flag {
border: 1px dashed #000;
width: 120px;
height: 120px;
top: 0px;
left: 0px;
text-align: center;
}
.g-flag:hover ~ .g-box {
transform: translate(0, 0);
transition: 0s;
}
.text-box {
width: 150px;
height: 150px;
text-align: center;
margin-top: 300px;
border: 1px dashed #000;
display: inline-block;
line-height: 150px;
}
</style>
</head>
<body>
<div class="g-wrap">
<div class="g-flag">FLAG</div>
<div class="g-box" draggable="true" ondrag="boxOnDrag(event)" ondragend="boxOnDragEnd(event)" ondragstart="boxOnDragStart(event)"></div>
</div>
<div class="text-box" ondrop="onDrop(event)" ondragover="onDragOver(event)" ondragleave="onDragLeave(event)">TEST</div>
</div>
</body>
<script>
var box = document.getElementsByClassName('g-box');
function boxOnDrag(event) {
// event.preventDefault();
}
function boxOnDragStart(event) {
// event.preventDefault();
}
function boxOnDragEnd(event) {
// event.preventDefault();
// box.setAttribute('transform', `translate(${event.clientX}}, ${event.clientY})`);
console.log(box);
}
function onDrop(event){
event.preventDefault();
console.log('onDrop');
}
function onDragOver(event) {
event.preventDefault();
console.log(event);
console.log('onDragOver');
}
function onDragLeave(event) {
event.preventDefault();
console.log('onDragLeave');
}
</script>
</html>
网友评论