PDA

View Full Version : جابجایی سه div



ramin149
چهارشنبه 11 اسفند 1389, 10:02 صبح
من در صفحه سه عدد div دارم می خوام وقتی رو دو تا div کناری کلید کنم اطلاعات داخل div های کناری به div اصلی انتقال پیدا کنه و اطلاعات div اصلی به div فرعی که کلید کردم بره
مانند سایت زیر
http://www.marriott.com/default.mi
من div هام رو به صورت زیر طراحی کردم
و فقط می خوام div سبز حرکت کنه و div قرمز سر جایش قرار بگیره

و هرچه فکر کردم من به نتیجه ای نرسیدم و نمی دونم چه شکلی این کار رو انجام بدم ؟:متفکر:

MSN_Issue
چهارشنبه 11 اسفند 1389, 10:21 صبح
این کار رو میتونید با JQuery انجام بدید

ramin149
چهارشنبه 11 اسفند 1389, 11:44 صبح
خوب چه شکلی می تونید نمونه کد قرار دهید

ramin149
دوشنبه 16 اسفند 1389, 17:38 عصر
مشکل کد من کجاست
این کد صفحه html من که دو div گذاشتم


<div id="div2" class="div2" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 261px; left: 664px; background-color:Aqua" onclick="loc(this);"></div>
<div id="div1" class="div1" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 290px; left: 475px; background-color:blue" onclick="loc(this);"></div>

این کد جاوااسکریپتم که داخل یک فایل js گذاشتم .

function loc(sender) {
var oldtag = document.getElementById(sender);
var oldW = oldtag.style.top;
var oldh = oldtag.style.left;
oldtag.style.top = "290";
oldtag.style.left = "475";
var div = document.getElementById("div1");
div.style.top = oldW;
div.style.left = oldh;
div.id = sender.id;
oldtag.id = "div1";
}

hossin.esm
دوشنبه 16 اسفند 1389, 23:24 عصر
تاپیک قبلی تون یه کد را براتون گذاشته بودم
http://barnamenevis.org/showthread.php?277166-اضافه-کردن-مقداری-به-خصوصیت-top-در-جاوااسکریپت






<!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 loc(sender) {
var t = getStyle(sender,'top');
t=t.replace('px','');
if(l=='auto')
{
t=sender.offsetTop;
}
var oldW = t;
var l = getStyle(sender,'left');
l=l.replace('px','');
if(l=='auto')
{
l=sender.offsetLeft;
}
var oldh = l;
if(oldW!=290 )
{
sender.style.top = "290px";
sender.style.left = "475px";
sender.style.zIndex='10';
var div = document.getElementById("div1");
div.style.top =oldW+'px';
div.style.left = oldh+'px';
div.style.zIndex='0';
div.id = sender.id;
sender.id = "div1";
}


}
</script>
</head>
<body>
<div id="div2" class="div2" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 261px; left: 664px; background-color:Aqua" onclick="loc(this);"></div>

<div id="div1" class="div1" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 290px; left: 475px; background-color:blue" onclick="loc(this);"></div>
</body>
</html>

ramin149
چهارشنبه 18 اسفند 1389, 19:20 عصر
سلام دوست عزیر و بابت کد بالا خیلی ممنونم ولی من به یک مشکلی دیگه برخورد گردم اگر من 3 div دیگه قرار بدم و این کد رو بهش نسیت بدم یک خورده به هم می خوره می شه در این مورد هم کمکم کنید (ببخشید که مزاحمت شدم دوباره خودم روی این قضیه فکر کردم ولی موفق نشدم ):خجالت::خجالت:

<!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).getPropertyValue(styleProp);
return y;
}
function loc(sender) {
var t = getStyle(sender, 'top');
t = t.replace('px', '');
if (l == 'auto') {
t = sender.offsetTop;
}
var oldW = t;
var l = getStyle(sender, 'left');
l = l.replace('px', '');
if (l == 'auto') {
l = sender.offsetLeft;
}
var oldh = l;
if (oldW != 290) {
sender.style.top = "290px";
sender.style.left = "475px";
sender.style.zIndex = '10';
var div = document.getElementById("div1");
div.style.top = oldW + 'px';
div.style.left = oldh + 'px';
div.style.zIndex = '0';
div.id = sender.id;
sender.id = "div1";
}
}
</script>
</head>
<body>
<div id="div6" class="div6"
style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 100px; left: 474px; background-color:Silver;"
onclick="loc(this);"></div>
<div id="div5" class="div5"
style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 126px; left: 235px; background-color:Olive;"
onclick="loc(this);"></div>
<div id="div4" class="div4"
style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 136px; left: 717px; background-color:Lime"
onclick="loc(this);"></div>
<div id="div3" class="div3"
style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 171px; left: 285px; background-color:Gray;"
onclick="loc(this);"></div>
<div id="div2" class="div2"
style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 175px; left: 665px; background-color:Aqua;"
onclick="loc(this);"></div>
<div id="div1" class="div1"
style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 220px; left: 471px; background-color:blue;"
onclick="loc(this);"></div>
</body>
</html>

hossin.esm
چهارشنبه 18 اسفند 1389, 22:40 عصر
<!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).getPropertyValue(styleProp);
return y;
}
function loc(sender) {
var t = getStyle(sender, 'top');
t = t.replace('px', '');
if (l == 'auto') {
t = sender.offsetTop;
}
var oldW = t;
var l = getStyle(sender, 'left');
l = l.replace('px', '');
if (l == 'auto') {
l = sender.offsetLeft;
}
var oldh = l;
var z=getStyle(sender, 'zIndex');
if (oldW != 290) {
sender.style.top = "290px";
sender.style.left = "475px";
sender.style.zIndex = '5';
var div = document.getElementById("div1");
div.style.top = oldW + 'px';
div.style.left = oldh + 'px';
div.style.zIndex = z;
div.id = sender.id;
sender.id = "div1";
}
}
</script>
</head>
<body>
<div id="div6" class="div6" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 100px; left: 474px; background-color:Silver;z-index:2;" onclick="loc(this);">6</div>
<div id="div5" class="div5" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 126px; left: 235px; background-color:Olive;;z-index:3;" onclick="loc(this);">5</div>
<div id="div4" class="div4" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 136px; left: 717px; background-color:Lime;z-index:3;" onclick="loc(this);">4</div>
<div id="div3" class="div3" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 171px; left: 285px; background-color:Gray;z-index:4;" onclick="loc(this);">3</div>
<div id="div2" class="div2" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 175px; left: 665px; background-color:Aqua;z-index:4;" onclick="loc(this);">2</div>
<div id="div1" class="div1" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 220px; left: 471px; background-color:blue;z-index:5;" onclick="loc(this);">1</div>
</body>
</html>

ramin149
چهارشنبه 18 اسفند 1389, 23:40 عصر
خیلی ببخشید ه من دوباره مزاحم شدم شرمنده ولی باز یکم مشکل داره کد و هنوز تقریبا به همون شکل (به نظر شما مشکل از مروگر من نیست firefox) خیلی ببخشید !!!

hossin.esm
پنج شنبه 19 اسفند 1389, 00:08 صبح
سلام دوست عزیز
خواهش میکنم
بله درست هست من با firefox تست نکرده بودم
کد را اصلاح کردم

<!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).getPropertyValue(styleProp);
return y;
}
function loc(sender) {
var t = getStyle(sender, 'top');
t = t.replace('px', '');
if (l == 'auto') {
t = sender.offsetTop;
}
var oldW = t;
var l = getStyle(sender, 'left');
l = l.replace('px', '');
if (l == 'auto') {
l = sender.offsetLeft;
}
var oldh = l;
var z=getStyle(sender, 'zIndex');
if(!z)
{
var z=getStyle(sender, 'z-Index');
}
if (oldW != 290) {
sender.style.top = "290px";
sender.style.left = "475px";
sender.style.zIndex = '5';
var div = document.getElementById("div1");
div.style.top = oldW + 'px';
div.style.left = oldh + 'px';
div.style.zIndex = z;
div.id = sender.id;
sender.id = "div1";
}
}
</script>
</head>
<body>
<div id="div6" class="div6" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 100px; left: 474px; background-color:Silver;z-index:2;" onclick="loc(this);">6</div>
<div id="div5" class="div5" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 126px; left: 235px; background-color:Olive;;z-index:3;" onclick="loc(this);">5</div>
<div id="div4" class="div4" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 136px; left: 717px; background-color:Lime;z-index:3;" onclick="loc(this);">4</div>
<div id="div3" class="div3" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 171px; left: 285px; background-color:Gray;z-index:4;" onclick="loc(this);">3</div>
<div id="div2" class="div2" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 175px; left: 665px; background-color:Aqua;z-index:4;" onclick="loc(this);">2</div>
<div id="div1" class="div1" style="position: absolute; width: 296px; height: 365px; cursor: pointer; top: 220px; left: 471px; background-color:blue;z-index:5;" onclick="loc(this);">1</div>
</body>
</html>

ramin149
پنج شنبه 19 اسفند 1389, 00:13 صبح
آقا خیلی ممنون خیلی بهم کمک گردی نمی دونم چه شکلی از شما تشکر کنم

ramin149
پنج شنبه 19 اسفند 1389, 16:20 عصر
دوست عزیز سلام من با این کد به یک مشکل بر خورد گردم مشکل هم اینه که با jquery رویداد mouseover نوشتم که بر اساس id ولی در اینجا id ها تغییر نمی کنند . در حالی که شما در چند خط آخر این کار را انجام داده اید ولی باز مشکل داره 67318

hossin.esm
شنبه 21 اسفند 1389, 16:53 عصر
دوست عزیز سلام
بله مشکل داره و برای حل این مشکل فکر کنم بهتر هست الگوریتم را عوض کنید.
یک نمونه دیگر را ضمیمه کردم ببینید امیدوارم مفید باشه.(البته مثال های زیادی وجود داره)