jQuery:你能用 jQuery 找到所选元素的不透明度吗?

发布于 2024-09-04 04:44:46 字数 354 浏览 3 评论 0原文

我有一个在一组列表元素上运行的过滤器,它将不太理想的元素的不透明度淡化至 0.25,但我希望它们的不透明度返回到 1,然后在悬停时返回到 0.25。这做起来相当简单吗?

我只是很难找到一种方法来获取所选元素的当前不透明度,以便我可以将其存储在变量中以供使用。

$('#centerPanel li').hover(function(){
        var currentOpacity = $(this).?????
        $(this).fadeTo(1,1);
    },
    function(){
        $(this).fadeTo(1,currentOpacity);
    });

I have a filter running on a set of list elements which fades the lesser desirable elements down to 0.25 opacity but I'd love to have their opacity return to 1 and then back down to 0.25 on hover over and out. Is this fairly simple to do?

I'm only having trouble finding a way to grab the selected element's current opacity so I can store it in a variable for use.

$('#centerPanel li').hover(function(){
        var currentOpacity = $(this).?????
        $(this).fadeTo(1,1);
    },
    function(){
        $(this).fadeTo(1,currentOpacity);
    });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

唯憾梦倾城 2024-09-11 04:44:46

尝试 $(this).css("opacity")

来源

Try $(this).css("opacity")

source

浮世清欢 2024-09-11 04:44:46

有完整的指南“使用 jQuery 在 MSIE 中获取当前不透明度”http: //zenverse.net/get-current-opacity-in-msie-using-jquery-cross-browser-codes/

代码:

function getopacity(elem) {
  var ori = $(elem).css('opacity');
  var ori2 = $(elem).css('filter');
  if (ori2) {
    ori2 = parseInt( ori2.replace(')','').replace('alpha(opacity=','') ) / 100;
    if (!isNaN(ori2) && ori2 != '') {
      ori = ori2;
    }
  }
  return ori;
}

//to use it
var currentopacity = getopacity('div.the-element');

there are complete guide "Get Current Opacity in MSIE using jQuery" http://zenverse.net/get-current-opacity-in-msie-using-jquery-cross-browser-codes/

code:

function getopacity(elem) {
  var ori = $(elem).css('opacity');
  var ori2 = $(elem).css('filter');
  if (ori2) {
    ori2 = parseInt( ori2.replace(')','').replace('alpha(opacity=','') ) / 100;
    if (!isNaN(ori2) && ori2 != '') {
      ori = ori2;
    }
  }
  return ori;
}

//to use it
var currentopacity = getopacity('div.the-element');
幸福不弃 2024-09-11 04:44:46
$('#centerPanel li').hover(function(){
    if(!$(this).is(':animated'))
       $(this).animate({opacity: 'toggle'}, 1000);
},
function(){
    if(!$(this).is(':animated'))
       $(this).animate({opacity: 'toggle'}, 1000);
});
$('#centerPanel li').hover(function(){
    if(!$(this).is(':animated'))
       $(this).animate({opacity: 'toggle'}, 1000);
},
function(){
    if(!$(this).is(':animated'))
       $(this).animate({opacity: 'toggle'}, 1000);
});
醉殇 2024-09-11 04:44:46

您需要在函数外部设置 mouseout opacity var,这将阻止您的函数更改该值。

nohoverOpacity = $('#centerPanel li').css("opacity");
hoverOpacity = 1;
dur = 1000;
$('#centerPanel li').hover(function(){
        $(this).fadeTo(dur,hoverOpacity);
    },function(){
        $(this).fadeTo(dur,nohoverOpacity);
});

这是你想要的吗? :)

You need to set the mouseout opacity var outside the function, this will prevent your function to change that value.

nohoverOpacity = $('#centerPanel li').css("opacity");
hoverOpacity = 1;
dur = 1000;
$('#centerPanel li').hover(function(){
        $(this).fadeTo(dur,hoverOpacity);
    },function(){
        $(this).fadeTo(dur,nohoverOpacity);
});

Is this what you want? :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文