vue使用mouseenter和mouseleave模拟Hove

2022-03-04  本文已影响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>
上一篇 下一篇

猜你喜欢

热点阅读