2011-10-12 68 views
0

我想加载一个扩展div内的html文档,我想动画展开。 因为它现在我只能设置一个高度,它动画,然后只显示其余。动画文件的高度jQuery

所以我想我想要它加载的内容,然后动画,基本上它说300px它应该是我的HTML文档的高度(这是不同的,因为它是我的投资组合中的不同项目)。

box_project2 HTML在单独的html文档中,应该定义动画高度。

链接到我的网站,在此可以通过点击某些顶级项目来查看相应的问题。 http://richardhedberg.com/portfolionew/index.html#

$('.thumbs2').click(function() { 
    var idStr = ("project/" + $(this).attr('id')); 
    var newHeight = 0; 
    $('#show2').animate({ height: '300px', opacity: 0 }, function() { 
     $('#workp').fadeIn('fast'); 
     $.scrollTo('#gohere', 300); 

     $('#show2').load(idStr, function() { 
      newHeight = $('#box_project2').outerHeight(); 
      $(this).animate({ height: newHeight }, 300, function() { 
       $('#show2').delay(200).animate({ opacity: 1 }, 800); 
       $('#close2').css({ 'display': 'block', 'height': '25px' }); 
      }); 
     }); 
    }); 
}); 




     <div id="close2"> 
     </div> 
     <div id="show2"> 
      <div id="box_project2"> 
      </div> 
     </div> 


.workp { 
background:#fff; 
position:relative; 
z-index:999; 
margin-bottom:30px; 


} 


#close2 { 
position:absolute; 
width:25px; 
height:24px; 
background:url(images/graphics/CloseIcon.png); 
right:0px; 
top:0px; 
z-index: 9999; 
display: none; 
margin-left:-30px; 



} 
#show2 { 
display: block; 
height: 0px; 
opacity: 1; 
margin-left:-30px; 
clear:both; 

} 

#box_project2 { 

background:#fff; 
text-align: left; 
clear:both; 
height:100%; 


} 
+0

我觉得你的动画,而它的不透明度为0。我不完全跟随,但如果你设置了在jsfiddle.net上的一个例子,它会更好地表达你的问题。 :) –

+0

http://richardhedberg.com/portfolionew/index.html#如果你想你可以看看我的网站。 –

回答

0

什么是你的问题?

首先你想做负载,然后在负载的回调动画?

但是,如果您想向用户显示已加载多少数据,那么首先您需要编写自己的动画类。然后在每一帧你加载的数据和回调你去下一帧。请注意,在这种情况下,您会动态更改网址,因为您无法控制来自某个ajax调用的数据。

+0

实际上,只有在动画完成时才会执行加载。如果我没有弄错,'animate()'的回调函数会在动画结束时执行。 – Dutchie432

+0

当然可以。我有点累。 :)刚刚编辑答案。 – freakish

+0

对不起,很可能不清楚,我想要的是切换我的项目与一个动画扩展div加载在单独的html文件(例如project1.html)。所以是的,我想要先加载文件,然后为其添加动画。 –

0

$(this).animate({ height: newHeight } 

也许应该有px单元追加并

$(this).animate({ height: newHeight + 'px' } 
+0

仍然只是为300px生成$(this).animate({height:newHeight}部分根本不动画。 –