2013-11-21 49 views
0

我成功地从另外两个人的高度设置元素的填充顶部,我认为除了当我调整页面大小时,我需要重新加载它以检索正确填充值。当使用JQuery重新加载时,为元素设置填充

这里是我的jQuery代码:

jQuery(document).ready(function($) { 

marge = ($(".items").height() - ($(".picture").outerHeight()*.4)) 

function resizeBottom() { 
    $("div.bottom").css("padding-top", marge + "px"); 
}; 
resizeBottom(); 

onResize = function() { $("div.bottom").css("padding-top", marge + "px"); } 
}); 

回答

0

您需要重新计算的调整大小处理

jQuery(document).ready(function ($) { 
    onResize = function() { 
     var marge = ($(".items").height() - ($(".picture").outerHeight() * .4)) 
     $("div.bottom").css("padding-top", marge + "px"); 
    } 
    onResize() 
}); 

我希望法onResize被添加为window resize事件处理函数的marge值对象

编写它的另一种方法是

//register the window resize handler 
$(window).resize(function() { 
    var marge = ($(".items").height() - ($(".picture").outerHeight() * .4)) 
    $("div.bottom").css("padding-top", marge + "px"); 
}).resize() 
+0

感谢您的有益答案,第二个解决方案的作品,但不是每一次,这真的很奇怪。我继续寻找。 – Thomas

0

看起来这是事件处理程序“.resize()”的工作。查看此页面了解详情。我希望这是你正在寻找的。 http://api.jquery.com/resize/

+0

谢谢,我已经阅读过。 – Thomas

相关问题