2012-02-19 45 views
0

我有一个jQuery的函数,根据滚动位置改变图像。这工作正常,当我使用我的正常样式表,但是当我的媒体查询踢,并且原始值更改我的jquery函数而不是获取媒体查询值它仍然在样式表中的原始值上工作。有没有一种方法来定义,所以jquery将捕捉当前正在使用的实际值?jquery抓取div(而不是我的css正常值)的媒体查询宽度值,并将其用于函数

这是jQuery函数:

var scpos = function(){ 
    $(window).scroll(function(){ 
    var wwidth = $(window).width(); 
    var spos1 = wwidth - 371; 
    var spos2 = spos1+wwidth; 
    var spos3 = spos2 + wwidth; 
    var spos4 = spos3 + wwidth + $('.rightporto').width(); 
    var spos5 = spos4 + wwidth + $('.leftclients').width(); 

    if(($(window).scrollLeft() >= 0)&& ($(window).scrollLeft() <= spos1)){ 
        $(".step").css('background','url(img/naboutus.png) 94% 5% no-repeat fixed'); 
       } else if(($(window).scrollLeft() > spos1)&& ($(window).scrollLeft() <= spos2)){ 
        $(".step").css('background','url(img/nwhatwedo.png) 94% 5% no-repeat fixed'); 
       } else if(($(window).scrollLeft() > spos2)&& ($(window).scrollLeft() <= spos3)){ 
        $(".step").css('background','url(img/ntheory.png) 94% 5% no-repeat fixed'); 
       } else if(($(window).scrollLeft() > spos3)&& ($(window).scrollLeft() <= spos4)){ 
        $(".step").css('background','url(img/nportfolio.png) 94% 5% no-repeat fixed'); 
       } else if(($(window).scrollLeft() > spos4)&& ($(window).scrollLeft() <= spos5)){ 
        $(".step").css('background','url(img/nclients.png) 94% 5% no-repeat fixed'); 
       }else { 
        $(".step").css('background','url(img/ncontacts.png) 94% 5% no-repeat fixed'); 
       } 



     }); 

这是我称它为rightporto类

$(window).resize(function() { 
scpos(); 
}) 
.resize();//trigger the resize event on page load 

我的主要样式表值:

.rightporto{ 
    float:left; 
width:2484px; 
} 

这是我的媒体rightporto类的查询值取决于分辨率,例如1366px宽度:

@media screen and (min-width: 1281px) and (max-width: 1366px) { 
      .rightporto{width:2000px;} 
    } 

所以我的问题,你可以看到的是,jquery函数只抓取我的主样式表中的宽度:2484px类rightporto宽度。所以,当我有一个1366宽度的决议,而不是获得类rightporto宽度:2000px它仍然获得2484px的主要;

有什么建议吗?

回答

0

CSS3“媒体查询”尚未在所有主流浏览器中实现。 #rightporto { width:2000px; }指令是否有可能未实现?

+0

有一个浏览器问题和事情werent工作。重新安装我的浏览器,一切正常。谢谢 – Chris 2012-02-20 09:03:53