0
我有一個側欄不斷檢查用戶的滾動位置,並根據其位置,在需要指明頁面上的哪一部分被瀏覽時,更改側欄上特定圖像的背景圖像。在本地查看此側欄時,我會看到側欄閃爍。滾動上的閃爍側邊欄
將它上傳到我的網站並在那裏查看後,閃爍停止,但以防萬一,我想知道是否有人知道爲什麼以及如何阻止它。我的網站可以在側邊欄中看到動作(它是位於左側的側欄,編號爲1,2,3和4)爲here。我的代碼如下。
$(document).scroll(function() {
var greenheight = document.getElementById('welcome_logo').offsetHeight;
var redheight = document.getElementById('slideins').offsetHeight;
var blueheight = document.getElementById('section_overview').offsetHeight;
var yellowheight = document.getElementById('howsiteworks').offsetHeight;
if($(window).scrollTop() > redheight){
if (navslide != 2) {
if($(window).scrollTop() < greenheight+redheight){
$('#side2').css("background-image", "url(images/sidebar/side2_over.fw.png)");
$('#side1').css("background-image", "url(images/sidebar/side1.fw.png)");
$('#side3').css("background-image", "url(images/sidebar/side3.fw.png)");
$('#side4').css("background-image", "url(images/sidebar/side4.fw.png)");
var navslide = 2
}
}
}
if($(window).scrollTop() < redheight)
if (navslide != 1) {
{
$('#side1').css("background-image", "url(images/sidebar/side1_over.fw.png)");
$('#side2').css("background-image", "url(images/sidebar/side2.fw.png)");
$('#side3').css("background-image", "url(images/sidebar/side3.fw.png)");
$('#side4').css("background-image", "url(images/sidebar/side4.fw.png)");
var navslide = 1
}
}
if($(window).scrollTop() > redheight+greenheight){
if (navslide!=3) {
if($(window).scrollTop() < greenheight+redheight+blueheight){
$('#side3').css("background-image", "url(images/sidebar/side3_over.fw.png)");
$('#side1').css("background-image", "url(images/sidebar/side1.fw.png)");
$('#side2').css("background-image", "url(images/sidebar/side2.fw.png)");
$('#side4').css("background-image", "url(images/sidebar/side4.fw.png)");
var navslide = 3
}
}
}
if($(window).scrollTop() > redheight+greenheight+blueheight){
if (navslide!=4) {
if($(window).scrollTop() < greenheight+redheight+blueheight+yellowheight){
$('#side4').css("background-image", "url(images/sidebar/side4_over.fw.png)");
$('#side1').css("background-image", "url(images/sidebar/side1.fw.png)");
$('#side2').css("background-image", "url(images/sidebar/side2.fw.png)");
$('#side3').css("background-image", "url(images/sidebar/side3.fw.png)");
var navslide = 4
}
}
}
});
我很難找到預加載的最佳方法,而且精靈也花了很多時間。我注意到在網站上時,它不會在我的任何瀏覽器上閃爍,只會在本地閃爍。你認爲值得修復嗎? – etangins