gpt4 book ai didi

jquery - 修改一个简单的 jquery 函数来改变图像的不透明度

转载 作者:太空宇宙 更新时间:2023-11-03 19:11:03 26 4
gpt4 key购买 nike

function toggle() {
if ($(this).is(".open")) {
$(this).animate({
width: 400
}, 500);
} else {
$(this).animate({
width: $(this).data("width")
}, 500);
}
$(this).toggleClass("open");
}
$("#portfolio_img1").click(function() {
if (!$(this).data("width")) {
var img = new Image();
var _this = $(this);
img.onload = function() {
_this.data("width", this.width);
toggle.call(_this);
}
img.src = $(this).css("backgroundImage").replace("url(\"", "").replace("\")", "");
} else {
toggle.call(this);
}
});

toggle 函数创建了一个类“.open”,它将图像宽度从裁剪后的宽度更改为全宽。在我的 CSS 中,我指定图像的不透明度为 0.5,在鼠标悬停时更改为 1 的不透明度。我还希望将类别为“open”的图像的不透明度更改为 1,但是当我在 CSS 中执行 .open { opacity: 1 } 时,它没有任何影响。我如何修改我的函数,以便在应用类“open”时图像不透明度更改为 1,而在删除类“open”时它又回到 0.5?谢谢

最佳答案

这样的事情可能会有所帮助:

//change from hover to check for class open in your case$(this).hover(      function() {          $(this).stop().animate({ opacity: 1.0 }, 800);      },      function() {          $(this).stop().animate({ opacity: 0.5 }, 800);      })});

希望对你有帮助

关于jquery - 修改一个简单的 jquery 函数来改变图像的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8282681/

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