jquery - 使用 JQuery 重新加载时将填充设置为元素

标签 jquery css

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

这是我的 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" ); }
});

最佳答案

您需要重新计算调整大小处理程序上的 marge

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

我希望方法 onResize 被添加为 window 对象的调整大小事件处理程序

另一种写法是

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

关于jquery - 使用 JQuery 重新加载时将填充设置为元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20134365/

相关文章:

javascript - 单击上一个文本字段时创建一个新的文本字段

jQuery .on 数据或事件处理程序?

html - 如何让这个内部div垂直居中? (使用CSS)

html - 影响其他导航元素的导航 Div

javascript - 即使在使用 javascript 重新加载后也保留滚动条位置

javascript - Twitter Bootstrap 在 Modal 中形成丑陋的形式

Jquery 终端文本格式化语法,我做错了什么?

jquery - 如何将内部 div 与外部 div 的底部对齐?

javascript - 将 jQuery 函数导入 Ember 错误 "i is not defined"

css - Icomoon - 我可以使用 icomoon chrome 插件在没有任何许可的情况下生成图标字体吗?