web之鼠标悬浮,鼠标移入和鼠标移出、hover、onmouseover、onmouseout、getElementById、mouseenter、mouseleave

92 篇文章 0 订阅
48 篇文章 1 订阅


1、关键代码

1.1、原生

鼠标经过(:hover)

.rotate_enlarge {
	border-left: 30px solid #0000ff;
    border-top: 30px solid #ff0000;
    border-right: 30px solid #00ff00;
    border-bottom: 30px solid #FFFF00;
    border-radius: 10%;
    width: 60px;
    height: 60px;
    line-height: 60px;
    background-color: transparent;
}

.rotate_enlarge:hover {
    transform: rotate(360deg) scale(1.2);
    -webkit-transform: rotate(360deg) scale(1.2);
    -moz-transform: rotate(360deg) scale(1.2);
    -o-transform: rotate(360deg) scale(1.2);
    -ms-transform: rotate(360deg) scale(1.2);
}

鼠标移入移出事件

let rotateEnlarge = document.getElementById('rotateEnlarge');
rotateEnlarge.onmouseover = function () {
	console.log('鼠标移入旋转放大元素');
};
rotateEnlarge.onmouseout = function () {
    console.log('鼠标移出旋转放大元素');
};

1.2、vue

鼠标经过(:hover)

.mouseover_mouseleave {
	width: 120px;
	height: 120px;
	line-height: 120px;
	text-align: center;
	background-color: #ff0000;
	color: #333;
}

.mouseover_mouseleave:hover {
	background-color: #0000ff;
	color: #eee;
}

鼠标移入移出事件

<div>
	<div @mouseenter="mouseOver">移入</div>
	<div @mouseleave="mouseLeave">移出</div>
</div>
// 移入
mouseOver() {
	this.msg = "";
	clearTimeout(this.times);
	this.msg = "鼠标移入";
},
// 移出
mouseLeave() {
	this.msg = "鼠标移出";
	this.times = setTimeout(() => {
		this.msg = "";
	}, 1000);
},

注意:当这两个方法绑定在组件上时,需要使用native来修饰。

<chi @mouseenter.native="mouseOvers" @mouseleave.native="mouseLeave"></chi>

2、效果演示

hover_onmouseover_onmouseout_gif


hover_onmouseover_onmouseout_png


3、完整代码

gitee(码云) - mj01分支 - hover_onmouseover_onmouseout 文件夹

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值