تغییر موقعیت یک المنت دکمه با جاوا اسکریپت
فایل اچتی ام الم اینه
کد:
<!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>
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
<script src="JScript1.js" type="text/javascript"></script>
<title></title>
</head>
<body>
<p>This is Title</p>
<hr />
<p>We are human so we must be careful about our society rights</p>
<button id="b1" type="button" onclick="func1(this,2)" >press :)</button>
<hr />
<p>This is the footer</p>
</body>
</html>
فایل سی اس اسم اسنه
کد:
body
{
background-image:url('backpic.jpg')
}
#tswcssbuttons li a {
color: #000 ;
background-color: #ffb200 ;
border: 1px outset #b37d00 ;
width: 180px ;
text-decoration: none ;
display: block ;
}
hr
{
border-bottom-color:Blue;
}
p
{
margin-left:120px;
}
button
{
position:fixed;
left:120px;
top:200px;
}
و جاوااسکریپتی رو لازم دارم که مثلا با کلیک روی دکمه جای دکمه به خونه 400px و 400px بپره.
مثلا
کد:
function func1(hnd, number) {
var theRules = new Array();
if (document.styleSheets[0].cssRules) {
theRules = document.styleSheets[0].cssRules;
} else if (document.styleSheets[0].rules) {
theRules = document.styleSheets[0].rules;
}
alert(theRules.length);
number = number-1;
if (number >= 0) func1(number);
}
البته این کار نمی کنه یعنی من تا اینجا رفتم ولی دیگه گیج شدم دو خط آخر تابع واسه اینه که می خواستم دکمه ه یه دفه جابجا نشه بلکه انیمیشن وار حرکت کنه که مهم نیست الان. الان فقط می خوام بدونم چطور میشه پوزیشن رو با جاوا اسکریپت تغییر داد.