【发布时间】:2018-02-22 17:18:54
【问题描述】:
我有下面的代码,当你向下滚动时淡入图像,当你向上滚动时淡出它们:
<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>
任何想法为什么当我将不透明度设置为 0.4 时这在 Safari 中不起作用?
我在 Safari 10.1.2 中进行测试。
【问题讨论】:
标签: jquery safari fadein fadeout