【发布时间】:2016-11-17 23:48:25
【问题描述】:
<script>
$('.image-wrapper').mouseenter(function(e) {
e.preventDefault();
$(this).removeClass('image-wrapper');
});
$('.boxer').mouseenter(function(){
$('.image_wrapper img').addClass('image_wrapper img:hover');
});
</script>
如你所见,我为我的背景 <div> 悬停效果删除了类。所以当我选择另一个<div> 时,只让背景<div> 悬停。
更新*我也试试这个。
<script>
var background = document.getElementById('.image-wrapper');
var background = false ;
$('.image-wrapper').mouseenter(function(e) {
e.preventDefault();
$(this).removeClass('image-wrapper');
background = true;
});
$('.boxer').mouseenter(function(){
if (background = true) {
$('.image-wrapper').addClass('image-wrapper');
} else {
$('.image-wrapper').removeClass('image-wrapper');
}
});
</script>
HTML:
<div id="info_01" class="image-wrapper info_all">
<img src="images/main_2/info_01.jpg" alt="" class="images">
<div class="boxer"><p class="boxer_title">ABOUT</p></div>
</div>
CSS:
#info_01 {
width:512px;
height:384px;
background:no-repeat;
position:absolute;
}
.image-wrapper {
font-size: 0;
overflow:hidden;
}
.image-wrapper img {
max-width: 100%;
transition: transform .3s ease-in-out;
}
.image-wrapper:hover img {
transform: scale(1.1);
}
【问题讨论】:
-
如果你删除了元素的
.image-wrapper类,第二个函数会自动找到元素。显示更多代码让我们了解您真正想要做什么。因为现在,你问的还不清楚,。 -
我不知道该怎么说。但也许我可以向你解释。假设我有一个带有 w:50px h:50px 的
,现在当我将其悬停时缩放到 1.1,然后我在 中有一个带有 w:10px h:10px 的 ,所以现在我做一个Jquery 删除 悬停效果。然后现在当我将鼠标移动到 时, 开始悬停。 -
我可以知道 document.getElementById('.class');因为通过“ID”获取元素,但最后我使用 .class 可以吗?
-
document.getElementById()是一种选择元素的 Javascript 方法。它绝对需要id。如果你想选择一个班级,请使用document.getElementsByClassName() -
但是我的意思是...如果您首先从元素中删除该类,则不能使用此类在第二个函数中选择元素...因为该类已被删除。展示您的 HTML 和 CSS(如果有)...也许我们会找到解决方案。
标签: jquery hover mouseenter