栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Vue.js

鼠标移入移出效果

Vue.js 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

鼠标移入移出效果

元素内遮罩层根据鼠标方向显示的效果比较常见,比如百度图片里的图片信息展示。自己动手实现jQuery插件版和Vue组件版效果。

原文链接

实现思路

1、根据鼠标的位置定位在元素内出现的方向
2、根据方向动态设置遮罩层样式
3、设置动画移动遮罩层

jQuery版

jQuery插件可以通过$.fn.extend方法进行拓展。

html
    
        
            

mouse hover

                                        

mouse hover

                                        

mouse hover

                                        

mouse hover

                                        

mouse hover

                                        

mouse hover

             
css
.container {    width: 600px;    margin: auto;    margin-top: 100px;
}.content {    float: left;    position: relative;    height: 150px;    width: 150px;    margin: 20px;    overflow: hidden;    background: #ccc;
}.content .shade {    position: absolute;    top: 0;    display: none;    width: 100%;    height: 100%;    line-height: 100px;    color: #fff;    background: rgba(0, 0, 0, 0.7);
}
js
Vue版

通用Vue的组件实现判断元素内鼠标的位置,利用插槽的方式显示遮罩层内容。

html
        
                mouse hover
        
        
                mouse hover
        
        
                mouse hover
        
        
                mouse hover
        
        
                mouse hover
        
        
                mouse hover
        
css

        html,        body {                text-align: center;                color: #000;                background-color: #353535;
        }

        * {                box-sizing: border-box;
        }        #app {                width: 600px;                margin: auto;                margin-top: 100px;
        }        .content {                float: left;                position: relative;                height: 150px;                width: 150px;                margin: 20px;                overflow: hidden;                background: #ccc;
        }        .content .shade {                position: absolute;                top: 0;                left: -100%;                width: 100%;                height: 100%;                line-height: 100px;                color: #fff;                background: rgba(0, 0, 0, 0.7);
        }
js
效果

image



作者:bestvist
链接:https://www.jianshu.com/p/f61505c3c09b


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/240891.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号