jquery動態計算menu菜單的高度

1. css

.menu_wrapper{
    width: 254px;
    background: #282828;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
}

2.dom元素

3.js代碼

  // 初始化菜單高度
    function setsize() {
        var max_h = $(".menu_wrapper_inner").height();
        var window_h = window.innerHeight;
        var body_h = $("body").height();

        if (max_h < window_h) max_h = window_h;
        if (max_h < body_h) max_h = body_h;
        $(".menu_wrapper").height(max_h);

        setTimeout(function () { setsize(); }, 100);
    }
    setsize();

    $(window).on('resize', function () {

        setsize();     
    })

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章