【发布时间】:2023-03-04 15:14:01
【问题描述】:
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。我还希望将具有“打开”类的图像的不透明度更改为 1,但是当我在 CSS 中执行 .open { opacity: 1 } 时,它没有任何影响。如何修改我的函数,以便在应用“open”类时,图像不透明度变为 1,而当“open”类被删除时,它又回到 0.5?谢谢
【问题讨论】:
-
CSS -> .open {opacity:1!important;} - 根据你添加该类的位置,你可能需要编写 .open img{opacity:1!important;}跨度>
标签: jquery css function opacity