تصف هذه المقالة طريقة JavaScript لتمكين طبقة DIV من التحرك بشكل مرن عن طريق النقر فوق زر. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
انسخ الرمز على النحو التالي: <! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title> انقر فوق الزر لجعل المؤثرات الخاصة للطبقة المرنة والهاتف المحمول </title>
<type type = "text/css">
#div1 {background: #ffcc66 ؛ الحدود:#ff6600 1px الصلبة ؛ الارتفاع: 100px ؛ العرض: 100px ؛ الموقف: قريب اليسار: 0px ؛}
</style>
<script type = "text/javaScript">
var t = null ؛
وظيفة StartMove ()
{
إذا (ر)
{
ClearInterval (t) ؛
}
t = setInterval (Move ، 30) ؛
}
var step = 0 ؛
حركة الوظيفة ()
{
var odiv = document.getElementById ("div1") ؛
Step+= (100-Odiv.OffSetLeft)/50 ؛
الخطوة = الخطوة*0.98
Odiv.Style.Left = Odiv.OffSetLeft+Step ؛
}
</script>
</head>
<body>
<div id = "div1">
</div>
<type type = "button" value = "move" onClick = "StartMove ()"/>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.