In diesem Artikel wird die Methode von JavaScript beschrieben, damit die Div -Schicht durch Klicken auf eine Schaltfläche elastisch verschoben werden kann. Teilen Sie es für Ihre Referenz. Die spezifische Implementierungsmethode lautet wie folgt:
Kopieren Sie den Code wie folgt: <! DocType html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<kopf>
<titels> Klicken Sie auf die Schaltfläche, um die Div -Schicht flexible und mobile Spezialeffekte </title> zu gestalten
<style type = "text/css">
#Div1 {Hintergrund: #ffcc66; Grenze:#FF6600 1PX Solid; Höhe: 100px; Breite: 100px; Position: Relativ; links: 0px;}
</style>
<script type = "text/javaScript">
var t = null;
Funktion startMove ()
{
if (t)
{
ClearInterval (t);
}
t = setInterval (Bewegung, 30);
}
var Schritt = 0;
Funktion move ()
{
var odiv = document.getElementById ("div1");
Schritt+= (100-odiv.offsetleft)/50;
Schritt = Schritt*0,98
odiv.style.left = odiv.offsetleft+Schritt;
}
</script>
</head>
<body>
<div id = "div1">
</div>
<input type = "button" value = "move" onclick = "startMove ()"/>
</body>
</html>
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.