jQuery根据窗口的高度添加垂直滚动条

时间:2015-09-18 11:24:59

标签: jquery

我有30个结果集,我想使用jQuery基于移动或浏览器高度添加动态垂直滚动条,即如果结果更多。

<div class="banklist">
    <h1>Pay using Netbanking</h1>
    <input name="" type="text" class="textbox" id="filter" onkeyup="this.setAttribute('value', this.value);" value="">
    <div class="list">
       <img src="images/logo_citi.gif" class="img">Citibank Online                            
    </div>
    <div class="list">
       <img src="images/logo_hdfc.gif" class="img">HDFC Bank
    </div>
    <div class="list">
       <img src="images/logo_hdfc.gif" class="img">ICICI Bank
    </div>
    <div class="list">
       <img src="images/logo_hdfc.gif" class="img">Andhra Bank
    </div>
    ...............
    ...............

2 个答案:

答案 0 :(得分:3)

//检查任何移动设备上的高度答案在于添加css overflow-y轴同样是在x轴上添加滚动“overflow-x”

jQuery的(文件)。就绪(函数(){

   if($('.banklist').height() > 120){
        $('.banklist').css('overflow-y','scroll');    
    }

});

答案 1 :(得分:0)

尝试获得身高。试试这个

 var BodyHeight = 0, body = window.document.body
 if (window.innerHeight) {
        BodyHeight = window.innerHeight;
    }
    else if (body.parentElement.clientHeight) {
        BodyHeight = body.parentElement.clientHeight;
    }
    else if (body && body.clientHeight) {
        BodyHeight = body.clientHeight;
    }