jquery动态获取窗口宽度

文章描述:

jquery动态获取页面宽度

html

<div class="container">banner</div>
<div class="window-property">
    页面宽度:
    <span class="window-w"></span>
</div>

jquery

获取

$(function(){
    $('.window-w').text($(window).width())
})

 

动态获取

var resizeTimer = null;
$(window).bind('resize', function (){
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function(){
            console.log("窗口发生改变了哟!");
            console.log($(window).width());
            $('.window-w').text($(window).width())
        } , 100);
});

 

发布时间:2022/01/20

发表评论