开发者

Expand/Collapse a div from one height to other height

I have a div with style

#thumb {
  position:absolute;
  top:365px;
  left:280px;
  z-index:0;
  width:500px;
  text-align:left;
  height:235px;
  overflow: hidden;
}

Now I am using javascript function to expand and collapse

function toggle_visibility(id) {
   var e = document.getElementById(id);
   var v = document.getElementById("viewall");
   if (e.style.overflow != 'visible')
   {
      v.innerText= "Collapse";
      e.style.overflow = 'visible';
   }
   else
   {
      v.innerText= "Expand";
      e.style.overflow = 'hidden';
   }
}

But I don't want to just overflow it.. I want to increase the hei开发者_如何学JAVAght of div when expanding and return back to height 235px when you collapse it.

How can I do that? I am newbie to javascript..Any help will be appreciated


hmm, did you try using this to set the height? it should work i think.

document.getElementById('idhere').style.height = divHeight+'100px';

where the number before the px is how much you want to add the height, use minus to take away height. also idhere is where you put in the id of the div. does it work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜