美文网首页
vue使用mouseenter和mouseleave模拟Hove

vue使用mouseenter和mouseleave模拟Hove

作者: 似朝朝我心 | 来源:发表于2022-03-04 00:21 被阅读0次

效果图:


代码:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title></title>
</head>
<style>
.box1 {
    width: 30px;
    height: 30px;
    cursor: pointer;
}
.box2 {
    width: 20px;
    height: 20px;
    position: relative;
    cursor: pointer;
}
.box1 .img1{
    height: 100%;
    width: 100%;
    
}
.box2 .img2{
    height: 100%;
    width: 100%;
}
.p {
    position: absolute;
    top: 20px;
    left: 5px;
    font-size: 6px;
    color: green;
    user-select: none;
}
</style>

<body>
    <div id="app">
        <div v-show="show1" class="box1">
            <img @mouseenter="enter" @mouseleave="leave"  class="img1" src="d.png" alt="">
        </div>
        <div v-show="show2">
            <div class="box2">
                <img class="img2" src="s.png" alt="">
                
            </div>
            <p class="p">收藏</p>
        </div>
        
        
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                show1:true,
                show2:false
            },
            methods: {
                enter (){
                    this.show1 = false
                    this.show2= true
                },
                leave (){
                    this.show1 =true
                    this.show2= false
                }
            },

        })
    </script>
</body>

</html>

相关文章

网友评论

      本文标题:vue使用mouseenter和mouseleave模拟Hove

      本文链接:https://www.haomeiwen.com/subject/iudprrtx.html