javascript - Javascript改变所有东西的不透明度,但悬停的图像
问题描述
http://vanhoesenarchitecture.com/completed-works/
我已经搜索并找到了一些选项,但没有一个有效。另外,在我的例子中,他们不是兄弟姐妹,所以我很难让它发挥作用。这是我正在使用的代码:
(function($){
jQuery('img').hover(function() {
jQuery('img').not(this).addClass('hovered');
console.log("HOVERED");
}, function() {
jQuery('img').removeClass('hovered');
console.log("NOT HOVERED");
});
})(jQuery);
CSS:
.hovered {opacity: 0.5;filter: alpha(opacity=50);}
任何帮助将不胜感激!
解决方案
/*(function($) {
jQuery('img').hover(
function() {
jQuery('img').not(this).addClass('hovered');
console.log("HOVERED");
},
function() {
jQuery('img').removeClass('hovered');
console.log("NOT HOVERED");
});
})(jQuery);
*/
$(document).ready(function() {
$('img').hover(
function() {
jQuery('img').not(this).addClass('hovered');
console.log("HOVERED");
},
function() {
jQuery('img').removeClass('hovered');
console.log("NOT HOVERED");
}
);
});
img {
width: 100px;
height: 100px;
}
img.hovered {
opacity: 0.5;
filter: alpha(opacity=50);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<img src='http://vanhoesenarchitecture.com/wp-content/uploads/2017/10/lone-pine-lodge-17.jpg'>
<img src='http://vanhoesenarchitecture.com/wp-content/uploads/2017/10/lone-pine-lodge-17.jpg'>
推荐阅读
- django - 'NoneType' 类型的参数对于 django 字符串“”是不可迭代的
- ios - 如何从 UI 选择器视图重新加载数据并使用转换关闭选择器视图
- c - 计算具有相同连续元素的块的元素数
- python-2.7 - 删除句号前的字符
- python - 在 Pytorch 中逐元素应用 Kullback-Leibler(又名 kl 散度)
- sql - 如何在 SSMS 2008 中执行 IF EXISTS UPDATE ELSE INSERT 语法
- javascript - 简化 semver 版本比较逻辑
- python - 如何在不换行的情况下打印完整的 NumPy 数组(在 Jupyter Notebook 中)
- docker - kata 容器可以用作沙箱来运行不受信任的代码吗?
- python - 在 Selenium 中一次加载多个 URL