Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  52] [ 3]  / answers: 1 / hits: 6864  / 10 Years ago, tue, may 13, 2014, 12:00:00

I want to fadeout my top image when I scroll down, so that it is completely black by the time it has scrolled off the page and completely normal when I am at the top of the page.



This is my JSFiddle.



This section of code:



<div class=jumbo midheight>
test<br />test
</div>


I have my background color as black so I was thinking it would be smart just to fadeout my background-image element but it seems that isn't possible.



Does this mean I have to put an overlay onto the div itself?

And if so, how do I do it?



Ideally I'd like to avoid adding an overlay div on top but I think I might have to.


More From » jquery

 Answers
0

You want to fade it to black, so - no, you can't fade a background image, but that's easy enough to get around. I used an overlay. I just positioned the div with the background image relative. Put another div inside and called it black overlay along with some added css and js.
CSS:



#blackOverlay{background-color:#000;opacity:0.0;position:absolute;top:0;width:100%;height:100%;}


JS:



  $('#blackOverlay').css('opacity',currentScrollTop/$('#blackOverlay').height());


Here's the fiddle http://jsfiddle.net/KCb5z/21/



I took out your js for simplicity, but you can see what I was going for there. that should get you started.




  • edit just saw you said you didn't want to use an overlay, but why not? easy solution.


[#45350] Sunday, May 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;