vue使用mouseenter和mouseleave模拟Hover效果

效果图:


代码:

<!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>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容