Node.js는 드래그 앤 드롭 및 흡착 코드 공유를 구현합니다.

小云云
풀어 주다: 2018-03-02 13:57:57
원래의
1801명이 탐색했습니다.

이 글은 주로 js 드래그 앤 드롭과 흡착 코드를 공유하는데, 도움이 되길 바랍니다.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
#big {
width: 500px;
height: 500px;
background-color: #ccc;
position: relative
}
#box {
width: 100px;
height: 100px;
background-color: #f00;
position: absolute
}
</style>
<script>
window.onload = function () {
var box = document.getElementById(&#39;box&#39;);
var big = document.getElementById(&#39;big&#39;);
// 鼠标在box中的位置
var disX = 0,
disY = 0;
box.onmousedown = function (e) {
var thisE = e || event;
disX = thisE.clientX - box.offsetLeft;
disY = thisE.clientY - box.offsetTop;
document.onmousemove = function (ev) {
var thisEvent = ev || event;
var l = thisEvent.clientX - disX;
var t = thisEvent.clientY - disY;
if (l < 20) {
l = 0;
} else if (l > big.offsetWidth - box.offsetWidth - 20) {
l = big.offsetWidth - box.offsetWidth;
}
if (t < 20) {
t = 0;
} else if (t > big.offsetHeight - box.offsetHeight - 20) {
t = big.offsetHeight - box.offsetHeight;
}
box.style.left = l + &#39;px&#39;;
box.style.top = t + &#39;px&#39;;
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
}
}
e.preventDefault();
}
}
</script>
</head>
<body>
<p id="big">
<p id="box"></p>
</p>
</body>
</html>
로그인 후 복사

관련 권장 사항:

마우스 끌기 div 예제를 구현하는 js 코드

js를 사용하여 파일 끌기를 제어하고 끌기 콘텐츠 획득

제한된 범위 끌기, 자기 흡착.

위 내용은 Node.js는 드래그 앤 드롭 및 흡착 코드 공유를 구현합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!