gpt4 book ai didi

css - jquery 获取 div 的媒体查询宽度值(而不是我的 css 正常值)并在函数中使用它

转载 作者:行者123 更新时间:2023-11-28 14:12:11 29 4
gpt4 key购买 nike

我有一个 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com