In diesem Artikel wird die Methode von JavaScript beschrieben, um Text- und Bildwiderstandseffekte zu implementieren. Teilen Sie es für Ihre Referenz. Die spezifische Implementierungsmethode lautet wie folgt:
Kopieren Sie den Code wie folgt: <html>
<kopf>
<titels> JavaScript erkennt den Drag & Drop -Effekt von Text und Bildern </title>
<style type = "text/css">
*{Padding: 0; Rand: 0;}
.tips {Position: absolut; Hintergrund: #eee;}
</style>
</head>
<body>
<div id = "tips1" onmouseover = "dragf.drag ('tips1');">
<img src = "/images/SkinsLogo.gif"> <br> Bild kann gezogen werden </div>
<div id = "tips2" onmouseover = "dragf.drag ('tips2');"> <a href = "// www.vevb.com" target = "_ leer"> wulin.com </a> <br/> Drag -Links sind auch in Ordnung.
</div>
</body>
<script type = "text/javaScript">
var $ id = function (id) {return document.getElementById (id);}
var dragf = {
gesperrt: falsch,
lastobj: undefiniert,
Drag: Funktion (obj) {
$ id (obj) .onmouseDown = function (e) {
var e = e? E: window.event;
if(!window.event) {e.preventDefault();}/* Prevent the default event of a,img in the annotation <a href='/site/js-5791-1.html' target='_blank'><u>Drag a,img under the browser</u></a>*/
Dragf.locked = true;
$ id (obj) .style.position = "absolut";
$ id (obj) .style.zindex = "100";
if (dragf.lastobj && dragf.lastobj!
dragf.lastobj.style.zindex = "1";
}
Dragf.Lastobj = $ id (OBJ);
var tempx = $ id (obj) .OffsetLeft;
var tempy = $ id (obj) .offsettop;
Dragf.x = e.clientX;
Dragf.y = e.clienty;
document.onmousemove = function (e) {
var e = e? E: window.event;
if (dragf.locked == false) return false;
$ id (obj) .style.left = tempx+e.clientx-dragf.x+"px";
$ id (obj) .style.top = tempy+e.clienty-dragf.y+"px";
if (window.event) {e.returnValue = false;}/* Blockieren Sie das Standardereignis von a, IMG unter IE*/
}
document.onmouseUp = function () {
Dragf.locked = false;
}
}
}
}
</script>
</html>
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.