我有一个隐藏的子导航高度设置为0.该div的内部是子导航的几个部分。第一次如何获得正确的div innerHeight?
我得到被点击的部分的名称,然后得到该div的innerHeight。然后使用该高度,我将从0到该值的.sub_navigation
高度设置为动画。但是,由于某种原因,第一次点击(获取值)时,它会关闭,太高,第二次完美。
你会如何解决这个问题?
角(从jQuery的转换)
// Controller for Nav
app.controller('NavController', function(){
// Property of Controller
this.clicked = function(menuItem) {
console.log(menuItem);
var contentHeight = $('.'+menuItem+'-content').innerHeight();
var content_height = $('.'+menuItem+'-content').innerHeight();
$('.sub_navigation').css({'height' : '0px'});
$('.'+menuItem+'-content').siblings().css({'display' : 'none'});
$('.'+menuItem+'-content').css({'display':'block', 'height':'auto'});
$('.sub_navigation').animate({
height: contentHeight
});
console.log('content_height = '+content_height);
console.log(contentHeight);
};
});
的jQuery
$(document).delegate(".navigation-links a", "click", function(){
var myContent = $(this).attr("data-content");
var contentHeight = $("."+myContent+"-content").innerHeight();
$("."+myContent+"-content").siblings().css({"display":"none"});
$("."+myContent+"-content").css({"display":"block", "height":"auto"});
$(".subNavigation").animate({
height: contentHeight
});
});
如果你点击增长,第一时间高度为400,第二次是266 :(
甜啊,就是这样! :) 谢谢 – 2014-09-25 18:39:46