作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 jquery 函数,它根据滚动位置更改图像。当我使用我的普通样式表时这很好用,但是当我的媒体查询开始并且原始值更改我的 jquery 函数而不是获取媒体查询值时它仍然适用于样式表中的原始值。有没有办法定义 jquery 将 carab 当前正在使用的实际值?
这是 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');
}
});
这就是我所说的
$(window).resize(function() {
scpos();
})
.resize();//trigger the resize event on page load
rightporto 类的主要样式表值:
.rightporto{
float:left;
width:2484px;
}
这是我的 rightporto 类的媒体查询值,具体取决于分辨率,例如 1366 像素宽度:
@media screen and (min-width: 1281px) and (max-width: 1366px) {
.rightporto{width:2000px;}
}
因此,正如您所见,我的问题是 jquery 函数仅在我的主样式表中获取类 rightporto 宽度,即 width: 2484px 。因此,当我的分辨率为 1366 宽度而不是获得类 rightporto width:2000px 时,它仍然获得主要的 2484px;
有什么建议吗?
最佳答案
CSS3“媒体查询”尚未在所有主流浏览器中实现。是否有可能 #rightporto { width:2000px;
指令没有实现?
关于css - jquery 获取 div 的媒体查询宽度值(而不是我的 css 正常值)并在函数中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9349218/
我有一个 jquery 函数,它根据滚动位置更改图像。当我使用我的普通样式表时这很好用,但是当我的媒体查询开始并且原始值更改我的 jquery 函数而不是获取媒体查询值时它仍然适用于样式表中的原始值。
我是一名优秀的程序员,十分优秀!