PDA

View Full Version : سوال: باز و بسته شدن div به صورت آهسته



aminghaderi
یک شنبه 03 بهمن 1389, 18:55 عصر
با سلام و احترام خدمت اساتید و دوستان گرامی
به وسیله جاوا اسکریپت چگونه می توانم یه Div رو به صورت آهسته باز کنم و به صورت آهسته ببندم؟؟؟

لطفا در صورت اطلاع راهنمایی فرمایید.:قلب:
با تشکر

hossin.esm
یک شنبه 03 بهمن 1389, 20:17 عصر
<!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 language="javascript">
var w=200;
var h=200;
function opendiv () {
var d= document.getElementById('div');
var cw=getStyle(d,'width').replace('px','');
var ch=getStyle(d,'height').replace('px','');
if(cw<w || ch<h)
{
if(cw<w)
{
d.style.width=(cw*1)+10+'px';
}
if(ch<h)
{
d.style.height=(ch*1)+10+'px';
}
setTimeout("opendiv()",1);
}
}
function closediv () {
var d = document.getElementById('div');
var cw=getStyle(d,'width').replace('px','');
var ch=getStyle(d,'height').replace('px','');
if(cw>0 || ch>0)
{
if(cw>0)
{
d.style.width=cw-10+'px';
}
if(ch>0)
{
d.style.height=ch-10+'px';
}
setTimeout("closediv()",1);
}
}
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;
}
</script>
</head>
<body>
<div style="position:relative;width:200px;height:200px;border: #000 thin solid;" id="div">
</div>
<div>
<button onclick="opendiv()">show</button>
<button onclick="closediv()">hide</button>
</div>
</body>
</html>

khani_prog
دوشنبه 04 بهمن 1389, 23:00 عصر
دوست عزيز اين كار با jquery بسيار ساده است .اين كار بدين صورت انجام ميگير د كه با استفاده از تابع hideو show امكان پذير است.
$('#div_detail_glass').hide();
البته بايستي كتابخانه jquery رو اضافه كني
از اينترنت ميتوني مطالب بيشتري پيدا كني خيلي ساده است