Home  >  Article  >  Web Front-end  >  如何根据不同的屏幕分辨率来显示不同的图片?_html/css_WEB-ITnose

如何根据不同的屏幕分辨率来显示不同的图片?_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:50:002022browse

如屏幕宽度小于1400时用图片1, 
大于时,用图片2,并且指定图片的宽度为屏幕的宽度。


回复讨论(解决方案)

定义 window.screen.width 传给后台输出.

<script> <br /> if(window.screen.width<1400){ <br /> document.write("<img src='img1.png' style="max-width:90%" text-align='center' alt="如何根据不同的屏幕分辨率来显示不同的图片?_html/css_WEB-ITnose" >"); <br /> }else{ <br /> document.write("<img src='img2.png' style="max-width:90%" text-align='center' alt="如何根据不同的屏幕分辨率来显示不同的图片?_html/css_WEB-ITnose" >"); <br /> } <br /> </script>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn