2011-10-15 30 views
0

可能重複:
Changing only y pos of background image via Jquery變化背景只有y位置滾動時

我想在滾動和保持x更改.nav-標誌backournd只有y位置-position consant。 我已經這樣實現,但沒有得到結果。 這裏是我使用的代碼

jQuery(document).ready(function($) { 
a=parseFloat(-28);// valor inccial para el background 1 
b=parseFloat(1);// valor inccial para el background 1 

var scrollTop = $(window).scrollTop();   
var scroll_actually= new Array();// identifica los valoares del background X y Y 

$(window).scroll(function(){//this is not the cleanest way to do this, I'm just keeping it short. 
    if(scrollTop>$(this).scrollTop()) // desplazamiento hacia arriba 
    { 
     if (getScrollTop()<=100 && getScrollTop()>=0)// identyifica cuando la posicion del background_1 esta en scroll 
     { 
       a=a+1;// posicion del background1 decrementa en 1 pixeles 
       b=b+1;// posicion de background1 decrementa en 1 pizeles 
       $('a.qa-logo-link').css('top', +a+'px'); 
       $('.nav-logo a').css('background-position', -1+'px' , 0+b+'px'); // i think something is wrong here 
     } 

    }scrollTop = $(this).scrollTop();}); 
}); 
function getScrollTop(){ 



    if(typeof pageYOffset!= 'undefined'){ 
     //most browsers 
     return pageYOffset; 
    } 
    else{ 
     var B= document.body; //IE 'quirks' 
     var D= document.documentElement; //IE with doctype 
     D= (D.clientHeight)? D: B; 
     return D.scrollTop; 
    } 
} 

,如果你想保持.nav-logo在固定位置,使用CSS position:fixed;position:absolute;並給予左側和頂部的值我的CSS文件

.nav-logo a{ 
background:url("logo1.png") no-repeat scroll transparent; 
background-position:-1px 1px;} 

回答

0

UPDATE

更新您的樣品

http://jsfiddle.net/SbuxT/9/

+0

我想保持位置個固定和改變.navlogo bakground的y位置,而滾動。 – Rajul

+0

是否意味着總是可見的標誌? –

+0

實際上,我想讓徽標向上移動,同時滾動瀏覽器欄,是的,我想讓總是可見。我只是在滾動時使用上面的代碼隨機定位。 – Rajul