javascript悬停在一个元素上会改变另一个元素
javascript-hovering one element changes other
我希望悬停一个元素会影响另一个元素。在这篇文章中,我想在悬停某个div
部分时,在其他div
的图像中创建动画。为此,我使用了以下代码:
HTML:
<div class="s">hover here</div>
<section>
<div class="hs-wrapper">
<img src="images/1.gif" alt="image01"/>
<img src="images/2.gif" alt="image02"/>
</div>
</section>
JavaScript:
$(document).ready(function () {
$(".s").mouseenter(function () {
$(".hs-wrapper img").css({
-webkit-animation-play-state:running;
-moz-animation-play-state: running;
-o-animation-play-state: running;
-ms-animation-play-state: running;
animation-play-state: running;
});
$(".s").mouseleave(function () {
$(".hs-wrapper img").css({
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
-ms-animation-play-state: paused;
animation-play-state: paused;
});
});
但它不起作用。请提供建议。
根据您提供的标记,您不需要jQuery。
只需使用选择器.s:hover + section .hs-wrapper img
。使用相邻的同级组合子+
,当鼠标悬停在.s
上时,可以选择下一个section
元素。从中选择子img
元素。
section .hs-wrapper img {
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
-o-animation-play-state: paused;
-ms-animation-play-state: paused;
}
.s:hover + section .hs-wrapper img {
-webkit-animation-play-state:running;
-moz-animation-play-state: running;
-o-animation-play-state: running;
-ms-animation-play-state: running;
animation-play-state: running;
}
下面是一个基本示例:
section .hs-wrapper img {
opacity:0;
transition: 3s ease-out; /* Mouseleave */
}
.s:hover + section .hs-wrapper img {
opacity:1;
transition: .5s ease; /* Mouseenter */
}
相关文章:
- innerHTML赢得't改变元素
- 可以't改变'name'元素的属性
- 为什么当我分配给element.style时,我的元素的样式没有改变
- 这是关于Jquery/JS的,如果我改变元素's HTML-我可以对它执行其他Jquery/JS操作吗
- 为什么硒会改变元素's href
- 有些元素没有被改变,即使它们应该被改变
- 从中删除元素后,javascript 数组的长度不会改变
- 如何使JQuery同位素与改变高度的元素一起工作
- javascript悬停在一个元素上会改变另一个元素
- 为什么我的
- 元素上的颜色属性没有改变我的 .hover() 事件处理程序
- 函数不能计算分数和改变页面元素的值
- 我希望我的操作改变它所附加的DOM元素
- Jquery在多个元素改变前调用函数
- 在图像元素改变了src之后,计时函数的运行时间
- 防止firefox在溢出元素改变时重置滚动条位置
- HTML范围元素改变CSS过滤器
- Knockout.js |可观察数组只在最后一个元素改变时触发
- jQuery自定义验证器方法在元素改变时被调用
- jQuery用子元素改变变量
- Div元素改变位置后的效果