简体   繁体   English

jQuery滚动,身高100%

[英]jQuery Scroll with 100% height body

I am attempting to fire a jQuery function when the window scrolls using the following code: 我试图在窗口使用以下代码滚动时触发jQuery函数:

$(window).scroll(function(){

However, when I set a body height of 100% (needed for formatting on the site), the scroll function does not fire. 但是,当我设置100%的身高(在网站上格式化所需)时,滚动功能不会触发。 The body height is set to 100% so that the background image fills the entire browser window. 正文高度设置为100%,以便背景图像填充整个浏览器窗口。

Is there any way that I can have the scroll function fired when scrolling, or an alternate function or alternate code to have a background image stretch the entire page? 有什么方法可以让我在滚动时触发滚动功能,或者一个替代功能或替代代码让背景图像拉伸整个页面?

Thank you 谢谢

Edit (My solution): 编辑(我的解决方案):

This was a bit of a weird question, as it had strict conditions - ie) the body heights, and other coding I've put in whilst playing around. 这是一个奇怪的问题,因为它有严格的条件 - 即身体高度,以及我玩的其他编码。

However I found that I had 但是我发现我有

overflow:auto;

set on a parent div just inside the body. 设置在正文内部的父div上。

The solution was to remove the overflow and add a 解决方案是去除溢出并添加一个

position:relative;

to the div surrounding all the content. 围绕所有内容的div。

This probably won't apply to anyone else, however I thought I'd post the solution just incase! 这可能不适用于其他任何人,但我认为我只是想发布解决方案!

Thanks for your help! 谢谢你的帮助!

Cheers Alex 干杯亚历克斯

You could specify background size like this: 您可以像这样指定背景大小:

body{
    background-image: url('http://images.google.com/intl/en_ALL/images/srpr/logo11w.png');
    background-size:100%;
    background-repeat:no-repeat;
}

and it will fill the entire browser window 它将填满整个浏览器窗口

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

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