整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

vue 鼠标移入移出事件

文实例为大家分享了vue实现鼠标移入移出事件的具体代码,供大家参考,具体内容如下:

html 代码

<div class="index_tableTitle clearfix" v-for="(item,index) in table_tit" :key="index">
          <div class="indexItem">
            <span :title="item.name">{{item.name}}</span>
            <span class="mypor">
              <i class="icon" @mouseenter="onMouseenter(index)" @mouseleave="onMouseleave"></i>
              <div v-show="vShow&&index==cur" class="index-show">
                <div  class="tip_Wrapinner">{{item.det}}</div>
              </div>
            </span>
          </div>
        </div>

js 代码

lt;!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>33-jquery移入移出事件</title>

<style type="text/css"> /*样式开始*/

*{ /*表示 所选取的该元素以及其所属的子元素 */

margin: 0; /*外边距*/

padding: 0; /*内边距*/

}

.father{ /* 选中class叫父亲的div盒子*/

width: 200px; /* 宽:200像素*/

height: 200px; /* 高:200像素*/

background: red; /* 背景:红色*/

}

.son{ /* 选中class叫儿子的div盒子*/

width: 100px; /* 宽:100像素*/

height: 100px; /* 高:100像素*/

background: #0000FF; /* 背景:蓝色*/

}

</style>

<script src="../static/js/jquery-3.6.0.js"></script> <!--引入jQuery 否则后面的$符号不能用 -->

<script>

$(function(){ /* jQuery 的入口函数 */

// alert('入口函数') /* 入口函数没有错误就会弹出 */

/*

mouseover mouseout 事件, 子元素被移入移出,也会触发父元素的事件

*/

// $(".father").mouseover(function(){ /*选择class叫父亲的div的鼠标移入事件*/

// alert('鼠标进入了父亲的盒子区域') /* 弹出窗口'鼠标进入了父亲的盒子区域'*/

// })

// $(".father").mouseout(function(){ /*选择class叫父亲的div的鼠标移出事件*/

// alert('鼠标移出了父亲的盒子区域') /* 弹出窗口'鼠标移出了父亲的盒子区域'*/

// })



/*mouseenter mouseleave 事件, 子元素被移入移出,不会触发父元素的事件 */

// $(".father").mouseenter(function(){ /*选择class叫父亲的div的鼠标移入事件*/

// alert('鼠标进入了父亲的盒子区域') /* 弹出窗口'鼠标进入了父亲的盒子区域'*/

// })

// $(".father").mouseleave(function(){ /*选择class叫父亲的div的鼠标移出事件*/

// alert('鼠标移出了父亲的盒子区域') /* 弹出窗口'鼠标移出了父亲的盒子区域'*/

// })


// $(".father").hover(function(){ /* 同时监听鼠标移入移出的事件用hover 子元素被移入移出,不会触发父元素的事件*/

// console.log('鼠标移入了') /* 移入后调用*/

// }, function(){

// console.log('鼠标移出了') /* 移出后调用*/

// })


$(".father").hover(function(){ /* 同时监听鼠标移入移出的事件用hover 子元素被移入移出,不会触发父元素的事件*/

console.log('鼠标移入移出了') /*鼠标移入和移出都监听了*/

})


})


</script>

</head>

<body>

<div class="father"> <!-- class叫父亲的div盒子 -->

<div class="son"> <!-- class叫儿子的div盒子 -->


</div>


</div>

</body>

</html>

、HTML

<img id="img1" src="luban.jpg" alt="" />

二、CSS

#img1{

opacity:0.3;

}

三、javascript

window.onload=function(){

var oImg=document.getElementById('img1');

oImg.onmouseover=function(){

startMove(100);

}

oImg.onmouseout=function(){

startMove(30);

}

}

var opac=30;

var timer=null;

fuicntion startMove(iTarget){

var oImg=document.getElementById('img1');

clearInterval(timer);

var iSpeed=0;

timer=setInterval(function(){

if(opac<iTarget){

iSpeed=1;

}else{

iSpeed=-1;

}

if(opac==iTarget){

clearInterval(timer);

}else{

opac+=iSpeed;

oImg.style.opacity=opac/100;

},30)

四、最终效果