简体   繁体   English

显示全屏图像,高度为100%,宽度为100%,但可以向下滚动

[英]Display a full screen image 100% height and 100% width but able to scroll down

I want to create a full screen image that let's me scroll down the page like on the apple site here. 我想创建一个全屏图像,让我像在苹果网站上一样向下滚动页面。

http://www.apple.com/uk http://www.apple.com/uk

You'll notice that by resizing the browser the image stays full screen but it allows you to scroll down to the footer. 您会注意到,通过调整浏览器的大小,图像可以保持全屏显示,但可以向下滚动到页脚。

Can this be done in jquery or does it need javascript? 可以在jquery中完成还是需要JavaScript?

The only bit of code i have so far is this css code that make the image full screen: 到目前为止,我唯一拥有的代码就是使图像全屏显示的CSS代码:

.content {
    height:100%;
    width:100%;
    background: url("http://america.aljazeera.com/content/ajam/watch/shows/the-stream/the-stream-officialblog/2013/9/16/indiana-ag-callsfordrugtestingofpregnantwomen/jcr:content/blog/mainpar/adaptiveimage/src.adapt.960.high.1379636395676.jpg") no-repeat center center fixed; 
    -webkit-background-size: cover;
       -moz-background-size: cover;
         -o-background-size: cover;
            background-size: cover;
}

and here's a fiddle fiddle http://jsfiddle.net/XXHgJ/ 这是一个小提琴小提琴http://jsfiddle.net/XXHgJ/

if you scroll down the footer shows but the menu stays still, this needs to scroll up. 如果向下滚动页脚显示,但菜单保持不变,则需要向上滚动。

If you just want to make a full screen element, you could do it with jQuery: 如果您只想制作一个全屏元素,则可以使用jQuery:

jQuery: jQuery的:

function setDimensions(){
   var windowsHeight = $(window).height();
   $('#element').css('height', windowsHeight + 'px');
}

//when resizing the site, we adjust the heights of the sections
$(window).resize(function() {
    setDimensions();
});

setDimensions();

CSS CSS

.content {
    background-image: url(yourURL);
    background-size:cover;

}

Living demo: http://jsfiddle.net/XXHgJ/7/ 现场演示: http//jsfiddle.net/XXHgJ/7/

Is it something like this?... I did it with pure css after closely noticing that in the one for apple when the page resizes, the image size does not necessarily change. 像这样吗?...我在注意到页面调整大小后的苹果版中,图像大小并不一定会改变,因此我用纯CSS做到了。

<div>

    <div style="position:relative; background:green; ">
     <div style="position:absolute; top:30px; left:50px; margin:auto; width:250px; height:40px; text-align:center; padding-top:10px; background:black; color:#fff;">Menu goes here</div>
        <div><img src="http://america.aljazeera.com/content/ajam/watch/shows/the-stream/the-stream-officialblog/2013/9/16/indiana-ag-callsfordrugtestingofpregnantwomen/jcr:content/blog/mainpar/adaptiveimage/src.adapt.960.high.1379636395676.jpg" height="400" /></div></div>

    <div style="background:#fff; padding:30px;">Footer</div>


</div>

See Feddle: http://jsfiddle.net/HZbAt/ 请参阅Feddle: http//jsfiddle.net/HZbAt/

Hope it helps 希望能帮助到你

on my page i have margin-top 80px which pushes the content down is their anything i can add to the code so this does not happen like -80px? 在我的页面上,我有80px的页边空白,可以将内容压低,因为它们可以添加到代码中,所以不会像-80px那样发生? This is for the jquery script 这是针对jquery脚本的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM