jQuery 使用jquery在单击时更改div的高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8389086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change height of div on click with jquery
提问by user1081953
I'm trying to expand the height of a div element with the following code:
我正在尝试使用以下代码扩展 div 元素的高度:
html:
html:
<div id="expandbtn">more..</div>
<div id="portfolio"><div class="itemweb" title="lol" rel="#derp"><div class="thumb"><img src="images/items/skills.jpg" title="Skills" rel="#derp"/></div>
script:
脚本:
$('#expandbtn').click(function(){
$('#portfolio').animate({height:'72px'}, 500);});
css:
css:
#portfolio {
width:914px;
height:295px;
margin:0 0 0 -8px;
overflow:hidden;}
But it won't work. What am i doing wrong?
但它不会工作。我究竟做错了什么?
回答by dku.rajkumar
your code is just fine. you can also try
你的代码很好。你也可以试试
$('#portfolio').css("height","74px");
try putting some backgroung color or image to visualize clearly
尝试添加一些背景颜色或图像以清晰地可视化
fiddle : http://jsfiddle.net/49HQM/4/
回答by user3470042
Try toload it when the document is ready:
当文档准备好时尝试加载它:
$(document).ready(function(){
$('#expandbtn').click(function(){
$('#portfolio').animate({height:'72px'}, 500);
});
回答by adeneo
It works just fine, but try setting position and a background color to see the element, like THIS FIDDLE.
它工作正常,但尝试设置位置和背景颜色以查看元素,例如THIS FIDDLE。
Also, it will not animate the height of the elements inside the portfolio div, if that is what you are trying to do (unless size of those elements are in percent)?
此外,它不会为投资组合 div 内元素的高度设置动画,如果这就是您要执行的操作(除非这些元素的大小以百分比表示)?