0
我有下面的代码,消失在你向下滚动的图像和淡化出来,当你向上滚动:淡入/淡出的滚动不工作在Safari
<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 the element is completely within bounds of the window, fade it in */
if (objectTop -500 < windowBottom) { //object comes into view (scrolling down)
if (jQuery(this).css("opacity")==0.4) {jQuery(this).fadeTo(1500,1.0);}
} else { //object goes out of view (scrolling up)
if (jQuery(this).css("opacity")==1.0) {jQuery(this).fadeTo(1500,0.4);}
}
});
}).scroll(); //invoke scroll-handler on page-load
});
</script>
<style>
.lookbook {opacity:0.4;}
</style>
这工作得很好,当我测试它在Chrome和Firefox,但不在Safari中。出于某种原因,如果我改变不透明度为0,将在Safari工作,即
<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 the element is completely within bounds of the window, fade it in */
if (objectTop -500 < windowBottom) { //object comes into view (scrolling down)
if (jQuery(this).css("opacity")==0) {jQuery(this).fadeTo(1500,1.0);}
} else { //object goes out of view (scrolling up)
if (jQuery(this).css("opacity")==1.0) {jQuery(this).fadeTo(1500,0);}
}
});
}).scroll(); //invoke scroll-handler on page-load
});
</script>
<style>
.lookbook {opacity:0;}
</style>
这是为什么在Safari中无法工作时,我设置不透明度为0.4任何想法?
我在Safari 10.1.2中测试。
谢谢!工作过一种享受。淡入淡出没有与jQuery的工作,所以我需要添加这个作为一个CSS过渡。不适用于旧浏览器,但我可以忍受这一点。 – a1anm