Resize element width on window resize jquery

安稳与你 提交于 2019-12-12 21:04:13

问题


I am computing elements width on page load with jq and works fine , trying to automate on window resize but kinda does not work. Desired effect: Boxes should auto resize on window resize and not drop down.

http://jsfiddle.net/yMcXm/4/

any help is appreciated . Thank you!


回答1:


Try $(window).resize See below,

$(document).ready(function() {
    var cw = $('#container').width();
    $(".box").width(cw / 5);

    $(window).resize(function() {
        var cw = $('#container').width();
        $(".box").width(cw / 5);
    });
});

Also used overflow property on the container and box_in, so that the elements/text inside are contained/hidden.. instead of going out.

DEMO: http://jsfiddle.net/skram/yMcXm/7/



来源:https://stackoverflow.com/questions/10984185/resize-element-width-on-window-resize-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!