如果浏览器宽度大于1000px,则显示图像

时间:2011-04-02 03:46:43

标签: javascript browser width

是否可以获取浏览器Web视图的宽度并在其大于1000px时对其进行操作?

示例(伪代码): 如果浏览器宽度大于1000px;

<div style="position:fixed; top:0; left:0; z-index:1; visibility:visible;">
<img src="images/borderleft.png">
</div>

1 个答案:

答案 0 :(得分:12)

现代方式:媒体查询

<div class="showWide">
<img src="images/borderleft.png">
</div>

// in your css file
.showWide {
   position:fixed; 
   top:0; 
   left:0; 
   z-index:1;
   visibility: hidden;
}

@media only screen and (min-width: 1000px) {
    .showWide {
        visibility: visible;
     }
}

2011 Way:JQuery

// returns width of browser viewport
if( $(window).width() > 1000)
{
  //add or unhide image.
}  

有关详情...... jquery width() documentation

相关问题