Change div width live with jQuery

前端 未结 5 1164
闹比i
闹比i 2021-01-01 13:54

Is it possible to change a div\'s width live with jQuery? And if it is, how?

What I want is to change its width depending on the browser\'s window width

5条回答
  •  时光说笑
    2021-01-01 14:36

    There are two ways to do this:

    CSS: Use width as %, like 75%, so the width of the div will change automatically when user resizes the browser.

    Javascipt: Use resize event

    $(window).bind('resize', function()
    {
        if($(window).width() > 500)
            $('#divID').css('width', '300px');
        else
            $('divID').css('width', '200px');
    });
    

    Hope this will help you :)

提交回复
热议问题