PDA

View Full Version : اضافه کردن مقداری به خصوصیت top در جاوااسکریپت



ramin149
جمعه 13 اسفند 1389, 00:36 صبح
سلام
من 1 هفته امدم سراغ جاوا اسکریت و داخل اینترنت هم در این مورد جستجو کردم ولی مشکل کد زیر رو نفهمیدم اگر میشه راهنمایی کنید

function ondiv(sender) {
var w = sender.style.top;
w = w + '10';
sender.style.top = w;
}

hossin.esm
شنبه 14 اسفند 1389, 08:20 صبح
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function getStyle(el,styleProp)
{
if (el.currentStyle)
var y = el.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(el,null).get PropertyValue(styleProp);
return y;
}
function ondiv(el)
{
var w = getStyle(el,'top');
w=w.replace('px','');
if(w=='auto')
{
w=el.offsetTop;
}
w = (w*1) + 10;
sender.style.top = w+'px';
}
</script>
</head>
<body>
<div id="sender" style="width:100px;height:100px;background:#666;position: absolute;" onmouseover="ondiv(this)"> </div>
</body>
</html>