jQ实现鼠标移入移出事件

当有多个相同的label标签时,当我鼠标移入标签时显示的突出显示效果。

HTML:

<li style="overflow-y: scroll;overflow-x: scroll;"><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板一</label><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板二</label><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板三</label><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板四</label><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板五</label><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板六</label><label style="display:inline-block;border-bottom: 1px solid #ccc;width: 120%;height:40px;line-height: 40px;"
							 class="el">模板七</label></li>

JS:

引入jQ:

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
var els= document.getElementsByClassName("el");
$(".el").each(function(index) {
	//移入事件
	$(this).mouseenter(function(obj) {
		els[index].style.backgroundColor = "#DBDBDB";
	});

})
$(".el").each(function(index){
	//移入事件
	$(this).mouseleave(function(obj){
		els[index].style.backgroundColor = "#FFFFFF";
	});
})

效果如下:

最后,祝大家圣诞节快乐

发布了128 篇原创文章 · 获赞 250 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/XU441520/article/details/103699893
今日推荐