简体   繁体   中英

jQuery Scroll with 100% height body

I am attempting to fire a jQuery function when the window scrolls using the following code:

$(window).scroll(function(){

However, when I set a body height of 100% (needed for formatting on the site), the scroll function does not fire. The body height is set to 100% so that the background image fills the entire browser window.

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.

The solution was to remove the overflow and add a

position:relative;

to the div surrounding all the content.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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