日常看到這種效果都是出如今FLASH全屏動畫網站上(用AS來控制),今天發現原來CSS也能夠實現這種效果。
核心代碼: php
html { background: url(bg.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }這種方法只支持Safari 3+,Chrome+,IE 9+, Opera 10+, FireFox 3.6+的瀏覽器。
文章的另外一個示例(用jQuery實現,支持IE7+ / Chrome / FireFox / Opera / Safari,但不支持IE6): http://css-tricks.com/examples/FullPageBackgroundImage/jquery.php css
另外附上相關案例和插件供參考:
一個全屏背景圖片網站:http://ringvemedia.com/,不過這個是用Mootools實現的,兼容IE6/7。 html
jQuery插件@jquery-backstretch:
http://srobbin.com/jquery-plugins/backstretch/#demo jquery
http://paulmason.name/media/demos/full-screen-background-image/ (這個不支持IE6) web
22個用全屏背景圖片的網站:
http://www.awwwards.com/22-css-websites-with-fullscreen-backgrounds.html 瀏覽器
HTML5瀏覽器全屏API示例:
http://blogs.sitepointstatic.com/examples/tech/full-screen/index.html 測試