2013-05-10 252 views
1

我有跟隨着代碼的HTML顯示圖片,顯示一張圖片:適合屏幕

<html> 
<head> 
<style>* {margin:0;padding:0;}</style> 
</head> 
<body style="margin: 0; padding: 0"> 
<center> 
<script type='text/javascript'><!--//<![CDATA[ 
    var m3_u = (location.protocol=='https:'?'URL1':'URL2'); 
    var m3_r = Math.floor(Math.random()*99999999999); 
    if (!document.MAX_used) document.MAX_used = ','; 
    document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u); 
    document.write ("?zoneid=1"); 
    document.write ('&amp;cb=' + m3_r); 
    if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used); 
    document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : '')); 
    document.write ("&amp;loc=" + escape(window.location)); 
    if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer)); 
    if (document.context) document.write ("&context=" + escape(document.context)); 
    if (document.mmm_fo) document.write ("&amp;mmm_fo=1"); 
    document.write ("'><\/scr"+"ipt>"); 
//]]>--></script><noscript><a href='URL3' target='_blank'><img src='URL4' border='0' alt=''/></a></noscript> 
</center> 
</body> 
</html> 

我要作出這樣的畫面適合屏幕,我試圖把WIDTH =「100% 「在img中,在href中...但它始終是相同的大小。

我該怎麼做?

+0

我猜你不明白JavaScript是做什麼的? – 2013-05-10 16:03:34

+0

我知道這段代碼顯示了一張圖片,我不在乎它是如何工作的,我只是想讓它變大。 – Jorge181 2013-05-10 16:08:25

回答

2

你可以使用backstretch jquery。 Backstretch是一個jQuery插件,允許您將動態調整大小的背景圖像添加到任何頁面。圖像將拉伸以適應頁面,並且會隨着窗口大小的改變而自動調整大小。

下面是一個例子:

http://srobbin.com/jquery-plugins/backstretch/

0

你可以做的是地方的圖像作爲背景元素,使元素覆蓋整個屏幕。 (你不需要任何JS爲,只有HTML和CSS)。
例子:

HTML

<a id="imgA" href='http://www.stackoverflow.com' target='_blank' /a> 

CSS

#imgA { 
    background-image: url(<url_to_img>); 

    /* Make the image cover the whole element area */ 
    background-size: 100%; 

    /* Make the element occupy the whole window */ 
    position: fixed; 
    top: 0px; 
    left: 0px; 
    width: 100%; 
    height: 100%; 
} 

現場演示here

(另請注意,如果你不需要鏈接功能,您可以用<div>更換<a>元素。)

0

按照文檔U可以通過添加背景覆蓋,以適應嘗試屏幕上的圖像

#img 
{ 
background:url(img.jpg); 
background-size:cover; 
}