I have an image即分辨率爲1920x1080。該圖像是由一個圖形團隊創建的,並且上面有很多文本/圖形。我不確定是否有CSS和/或JavaScript/jQuery的方式,當頁面加載時,此圖像在加載時佔用屏幕的100%。用戶然後可以向下滾動瀏覽並查看頁面內容的其餘部分。其上有圖形/文字至100%寬度/高度的適合/縮放圖像
現在我想這樣的事情(使用自舉):
<header>
<img src="http://az860851.vo.msecnd.net/release/site/3DScantoPrint_landing_hero.jpg" class="img-responsive" />
<div id="event-callout">
Ciudad de México Marzo 7th o Marzo 8th 2016
</div>
</header>
它不工作了太清楚,因爲隨着視口大小開始接近1770px,圖像開始比高度垂直高因此導致圖像中的一些文本從頁面滾動。
我想讓圖像適合屏幕尺寸(在頁面高度的100%負載下)。我已經嘗試過涉及jQuery和CSS的多種解決方案,但似乎都不符合這些基本要求。它甚至有可能嗎?
編輯:這裏
#hero {
background-image: url(http://az860851.vo.msecnd.net/release/site/3DScantoPrint_landing_hero.jpg);
background-size: cover;
position: relative;
height: 100vh;
}
<wrapper id="wrapper">
<div id="hero"></div>
</wrapper>
的另一種嘗試這種解決方案並不像不適合屏幕,因爲它按比例縮小。
編輯2:jQuery的嘗試這裏
#hero{
background-image:url(http://az860851.vo.msecnd.net/release/site/3DScantoPrint_landing_hero.jpg);
background-size:cover;
position:relative;
}
<wrapper id="wrapper">
<div id="hero"></div>
</wrapper>
$(window).scroll(function (e) {
handleScroll();
});
function fullscreen() {
$('#hero').css({
width: $(window).width(),
height: $(window).height()
});
}
fullscreen();
// Run the function in case of window resize
$(window).resize(function() {
fullscreen();
});
得到相同的結果,因爲它似乎在CSS版本。
你可以發佈你的嘗試,特別是你的CSS嘗試嗎? – Michelangelo
@Mikey增加了CSS和jQuery嘗試。以下[本指南](http://www.web2feel.com/creating-a-fullscreen-hero-div-for-your-site-header/) – mariocatch
我認爲你缺少背景圖像的一些CSS規則:你試過這個:https://css-tricks.com/perfect-full-page-background-image/ – Michelangelo