Forum Moderators: open
<script>
jQuery(window).on("load",function() {
jQuery(window).scroll(function() {
var windowBottom = jQuery(this).scrollTop() + jQuery(this).innerHeight();
jQuery(".lookbook").each(function() {
/* Check the location of each desired element */
var objectTop = jQuery(this).offset().top + jQuery(this).outerHeight();
if (objectTop -500 < windowBottom) { //object comes into view (scrolling down)
if (jQuery(this).hasClass("transparent_class")) {jQuery(this).addClass("visible_class").removeClass("transparent_class");}
} else { //object goes out of view (scrolling up)
if (jQuery(this).hasClass("visible_class")) {jQuery(this).addClass("transparent_class").removeClass("visible_class");}
}
});
}).scroll();
});
</script> <style>
.transparent_class {
/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";
/* IE 5-7 */
filter: alpha(opacity=40);
/* Netscape */
-moz-opacity: 0.4;
/* Safari 1.x */
-khtml-opacity: 0.4;
/* Good browsers */
opacity: 0.4;
transition: opacity 0.8s ease-in-out;
-moz-transition: opacity 0.8s ease-in-out;
-webkit-transition: opacity 0.8s ease-in-out;
}
.visible_class {
/* IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
/* IE 5-7 */
filter: alpha(opacity=100);
/* Netscape */
-moz-opacity: 1.0;
/* Safari 1.x */
-khtml-opacity: 1.0;
/* Good browsers */
opacity: 1.0;
transition: opacity 0.8s ease-in-out;
-moz-transition: opacity 0.8s ease-in-out;
-webkit-transition: opacity 0.8s ease-in-out;
}
</style> <img class="lookbook transparent_class" src="/1.jpg" />
<img class="lookbook transparent_class" src="/2.jpg" />
<img class="lookbook transparent_class" src="/3.jpg" />
<img class="lookbook transparent_class" src="/4.jpg" />
<img class="lookbook transparent_class" src="/5.jpg" />
<img class="lookbook transparent_class" src="/6.jpg" />
<img class="lookbook transparent_class" src="/7.jpg" />
<img class="lookbook transparent_class" src="/8.jpg" /> ' mark up of the post, so it is not clear what is and isn't supposed to be commented out.
Is there a reason why you don't simply use $.fadeIn() and $fadeOut()?
http://api.jquery.com/fadein/
Something like this:
[code]
/*place this at the bottom of your page just above the closing body tag </body>*/
<script>
$(window).scroll(function() {
var windowBottom = jQuery(this).scrollTop() + jQuery(this).innerHeight();
var objectTop = jQuery(this).offset().top + jQuery(this).outerHeight();
if (objectTop -500 < windowBottom) {
/*object comes into view (scrolling down)*/
$('.lookup').fadeIn('slow');
} else {
/*object goes out of view (scrolling up)*/
$('.lookup').fadeOut('slow');
}
});
</script>
<script>
jQuery(window).on("load",function() {
jQuery(window).scroll(function() {
var windowBottom = jQuery(this).scrollTop() + jQuery(this).innerHeight();
jQuery(".lookbook").each(function() {
var objectTop = jQuery(this).offset().top + jQuery(this).outerHeight();
if (objectTop -500 < windowBottom) {
if (jQuery(this).hasClass("transparent_class")) {jQuery(this).addClass("visible_class").removeClass("transparent_class");}
} else {
if (jQuery(this).hasClass("visible_class")) {jQuery(this).addClass("transparent_class").removeClass("visible_class");}
}
});
}).scroll();
});
</script>
could they only start to fade once the majority (e.g. 75%) of the image has left the screen
if (objectBottom > windowBottom + 500)
var windowSize = windowBottom - windowTop
if (objectBottom > windowBottom + (windowSize * 0.50) )