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