บทความนี้อธิบายถึงวิธีการของ JavaScript เพื่อเปิดใช้งาน DIV Layer เพื่อย้ายอย่างยืดหยุ่นโดยคลิกปุ่ม แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <! 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">
<head>
<title> คลิกปุ่มเพื่อให้เลเยอร์ Div มีความยืดหยุ่นและเอฟเฟกต์พิเศษมือถือ </title>
<style type = "text/css">
#div1 {พื้นหลัง: #ffcc66; ชายแดน:#FF6600 1px Solid; ความสูง: 100px; ความกว้าง: 100px; ตำแหน่ง: ญาติ; ซ้าย: 0px;}
</style>
<script type = "text/javascript">
var t = null;
ฟังก์ชั่น startmove ()
-
ถ้า (t)
-
ClearInterval (t);
-
t = setInterval (ย้าย, 30);
-
var step = 0;
ฟังก์ชั่นย้าย ()
-
var odiv = document.getElementById ("div1");
ขั้นตอน+= (100-odiv.offsetleft)/50;
ขั้นตอน = ขั้นตอน*0.98
odiv.style.left = odiv.offsetleft+ขั้นตอน;
-
</script>
</head>
<body>
<div id = "div1">
</div>
<อินพุต type = "ปุ่ม" value = "ย้าย" onclick = "startMove ()"/>>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน