2012-04-25 62 views
3

我在移動網站上爲不支持固定位置的移動瀏覽器僞造了頁腳的固定位置。 (iOS版的iOS 5,安卓2.2之前,等前)如何在使用JQuery更改CSS時添加淡入淡出效果

這裏是我使用的jQuery代碼,它工作得很好,做什麼,我想:

function changeFooterPosition() { 
    $('.not-fixed').css('top', window.innerHeight + window.scrollY - 56 + "px"); 
} 

$(document).bind('scroll', function() { 
    changeFooterPosition(); 
}); 

使作品。

我的問題是,我想添加一個小小的延遲,讓頁腳淡入視圖中,而不是在每次滾動後快速抓取。我環顧四周,發現下面的方法我可以使用,但我「不能確定他們是否是正確的人或者將其添加到上面的JS。

.delay(1000).fadeTo('slow', 1) 

我知道這個功能中存在的JQuery手機,但我不希望使用jQuery Mobile的整體只是這一個小東西。

在此先感謝。

+0

延遲和fadeTo在「正常」的jQuery – 2012-04-25 20:19:48

回答

0

嘗試動畫功能

這是不會掉色的,但應反而順利移動。

function changeFooterPosition() { 
    $('.not-fixed').animate({'top': window.innerHeight + window.scrollY - 56 + "px"}, 2000); 
} 

$(document).bind('scroll', changeFooterPosition); 
0

變化

$(document).bind('scroll', function() { 
    changeFooterPosition(); 
}); 

$(document).bind('scroll', changeFooterPosition); 

變化

$('.not-fixed').css('top', window.innerHeight + window.scrollY - 56 + "px"); 

var WantedSpeed = 2000; 
$('.not-fixed').delay(1000).animate({ 
    top: window.innerHeight + window.scrollY - 56 + "px" 
}, WantedSpeed, function() { 
    // Animation complete. 
}) 
0

你想要做什麼是油門您的滾動回調:

(function() { 
    var scrollTimer = 0, 
     $notFixed = $('.not-fixed'); 

    function changeFooterPosition() { 
    $notFixed.css('top', window.innerHeight + window.scrollY - 56 + "px").show(300); 
    } 

    $(document).bind('scroll', function() { 
    $notFixed.hide(); 
    clearTimeout(scrollTimer); 
    setTimeout(changeFooterPosition, 50); 
    }); 
}()); 
+0

存在還想說,有些設備需要當用戶滾動屏幕快照..所以設備本質上是滾動圖像。這是出於性能原因而完成的......但是這會導致頁腳在某些設備上滾動時可見。這是沒有辦法的。快照發生在滾動處理程序觸發之前。 – 2012-04-25 20:30:58

相關問題