鼠标悬浮,边框div边框的动画样式,效果图如下:

首先定义div及其样式:

 <style>
.show
{
width:300px;
height:200px;
border:1px solid red;
background:yellow;
}
</style>
<div class="show"></div>

界面展示效果如下:

通过指定样式clip来指定,裁剪的区域:

然后需要做的是将这个裁剪过程用动画连贯起来,修改css样式

    .show
{
position: absolute;
width: 300px;
height: 200px;
top: 400px;
left: 400px;
bottom: 400px;
right: 400px;
border:1px solid red;
animation: ClipAfter 4s linear infinite;
background: yellow;
}
@keyframes ClipAfter {
0%, 100% {
/*为了在动画过程中能保留右边框和下边框,rect的right和bottom分别多取两个像素*/
/*为了在动画的终点和起点不要显示上边框和左边框,rect的top和left分别多取了一个像素*/
clip: rect(1px,302px,202px,1px);
}
25% {
clip: rect(100px,302px,202px,150px);
} 50% {
clip: rect(200px,302px,202px,300px);
}
75% {
clip: rect(100px,302px,202px,150px);
}
}

更改之后的效果图如下:

同样可以定义出保留上边框和左边框的动画样式:

   @keyframes ClipBefore {
100%,0%{
clip:rect(0px,300px,200px,0px);
}
25%
{
clip:rect(0px,150px,100px,0px);
}
50%{
clip:rect(0px,0px,0px,0px);
}
75%{
clip:rect(0px,150px,100px,0px);
}
}

由于开篇示例中的动画,是左上,和右下方边框的动画是同步进行的,所以使用div的伪类before(实现左上边框动画),after(实现右下边框动画)

css:

     .region-wrap {
width: 320px;
height: 220px;
border: 1px solid #f4f4f4;
} .region {
position: absolute;
}
.content
{
position: absolute;
top: 10px;
left: 10px;
width: 300px;
height: 200px;
border:1px solid #aa0507;
}
.content:before,.content:after
{
position: absolute;
top:;
right:;
bottom:;
left:;
color: #A0A0A0;
content: '';
box-sizing: border-box;
margin: -10px;
z-index: -1;
}
.content:before
{
/*background: #cc1234;*/
box-shadow: inset 0 0 0 1px;
animation: ClipBefore 4s linear infinite;
}
.content:after
{
box-shadow: inset 0 0 0 2px;
animation: ClipAfter 4s linear infinite;
/*由于图片展示的区域比外边框小,所以这里要重新定位after的展示位置*/
top: 18px;
bottom: 0px;
right: 0px;
left: 18px;
}
.content>img
{
width: 300px;
height: 200px;
} @keyframes ClipAfter {
0%, 100% {
clip: rect(0px,302px,202px,0px);
}
25% {
clip: rect(100px,302px,202px,150px);
} 50% {
clip: rect(200px,302px,202px,300px);
}
75% {
clip: rect(100px,302px,202px,150px);
}
}
@keyframes ClipBefore {
100%,0%{
clip:rect(0px,300px,200px,0px);
}
25%
{
clip:rect(0px,150px,100px,0px);
}
50%{
clip:rect(0px,0px,0px,0px);
}
75%{
clip:rect(0px,150px,100px,0px);
}
}
@keyframes ClipAfter {
0%, 100% {
/*为了在动画过程中能保留右边框和下边框,rect的right和bottom分别多取两个像素*/
/*重新定位后,为了在动画的终点和起点不要显示上边框和左边框,rect的top和left分别多取了二个像素*/
clip: rect(2px,302px,202px,2px);
}
25% {
clip: rect(100px,302px,202px,150px);
} 50% {
clip: rect(200px,302px,202px,300px);
}
75% {
clip: rect(100px,302px,202px,150px);
}
}

html:

 <div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg.jpg"/>
</div>
</div>
</div>

效果如下:

最后,利用flex布局,放入以列表的形式展示,并将样式应用到hover伪类中

html

 <div class="showwindow-wrap">
<div class="showwindow">
<ul class="li-items">
<li>
<div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg1.jpg"/>
</div>
</div>
</div>
</li>
<li>
<div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg1.jpg"/>
</div>
</div>
</div>
</li>
<li>
<div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg1.jpg"/>
</div>
</div>
</div>
</li>
<li>
<div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg.jpg"/>
</div>
</div>
</div>
</li>
<li>
<div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg.jpg"/>
</div>
</div>
</div>
</li>
<li>
<div class="region-wrap">
<div class="region">
<div class="content">
<img src="./images/show-window/timg.jpg"/>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>

css

.showwindow-wrap
{
width: 100%;
display:flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.showwindow
{
width:1200px;
flex:;
background: #f4f4f4;
}
.li-items
{
margin: 0px;
padding: 0px;
display:flex;
flex-direction: row;
align-items: flex-start;
flex-wrap: wrap;
justify-content: center;
}
.li-items>li
{
float: left;
width: 323px;
height: 222px;
overflow: hidden;
margin-left: -2px;
margin-top: -1px;
}
.region-wrap {
width: 320px;
height: 220px;
border: 1px solid #f4f4f4;
} .region {
position: absolute;
}
.content
{
position: absolute;
top: 10px;
left: 10px;
width: 300px;
height: 200px;
/*border:1px solid #aa0507;*/
}
.content:before,.content:after
{
position: absolute;
top:;
right:;
bottom:;
left:;
color: #ea0c0c;
content: '';
box-sizing: border-box;
margin: -10px;
z-index:;
}
.content:hover
{
cursor: pointer;
}
.content:hover:before
{
top: -1px;
right:;
bottom:;
left: -1px;
box-shadow: inset 0 0 0 1px;
animation: ClipBefore 4s linear infinite;
}
.content:hover:after
{
box-shadow: inset 0 0 0 1px;
animation: ClipAfter 4s linear infinite;
/*由于图片展示的区域比外边框小,所以这里要重新定位after的展示位置*/
top: 18px;
bottom: 0px;
right: 0px;
left: 18px;
}
.content>img
{
width: 300px;
height: 200px;
} @keyframes ClipAfter {
0%, 100% {
clip: rect(0px,302px,202px,0px);
}
25% {
clip: rect(100px,302px,202px,150px);
} 50% {
clip: rect(200px,302px,202px,300px);
}
75% {
clip: rect(100px,302px,202px,150px);
}
}
@keyframes ClipBefore {
100%,0%{
clip:rect(0px,300px,200px,0px);
}
25%
{
clip:rect(0px,150px,100px,0px);
}
50%{
clip:rect(0px,0px,0px,0px);
}
75%{
clip:rect(0px,150px,100px,0px);
}
}
@keyframes ClipAfter {
0%, 100% {
/*为了在动画过程中能保留右边框和下边框,rect的right和bottom分别多取两个像素*/
/*重新定位后,为了在动画的终点和起点不要显示上边框和左边框,rect的top和left分别多取了二个像素*/
clip: rect(2px,302px,202px,2px);
}
25% {
clip: rect(100px,302px,202px,150px);
} 50% {
clip: rect(200px,302px,202px,300px);
}
75% {
clip: rect(100px,302px,202px,150px);
}
}
*{
font-size:12px;
list-style: none;
color: rgba(146, 248, 206, 0.91);
}

效果如开篇所发.

实现鼠标悬停,div勾画div边框的动画的更多相关文章

  1. CSS鼠标悬停图片加边框效果,不位移的方法

    <!DOCTYPE HTML> <html lang="en-US"> <head> <title>css实现鼠标悬停时图片加边框效 ...

  2. 【MFC】MFC DLEdit 设计属于自己的编辑框_鼠标悬停

    MFC DLEdit 设计属于自己的编辑框 2012-02-04 13:00 by 捣乱小子, 3543 阅读, 5 评论, 收藏, 编辑 起因 无意间看到了大牛们写的自定义编辑框控件,于是找了个时间 ...

  3. 鼠标悬停显示CSS3动画边框

    效果体验:http://keleyi.com/keleyi/phtml/css3/14.htm 以下是代码: <!DOCTYPE html> <html xmlns="ht ...

  4. css3鼠标悬停图片边框线条动画特效

    css3鼠标经过内容区时,边框线条特效效果制作.   html: <div class="strength grWidth hidden"> <div class ...

  5. 使用JS制作一个鼠标可拖的DIV(一)——鼠标拖动

    使用 JS 来实现一个可拖动的DIV,主要是使用到以下几个事件: 1.鼠标按下:DIV元素的onmousedown. 2.鼠标按住拖动:document 的 onmousemove 元素. 3.鼠标放 ...

  6. 如何给div加一个边框border样式

    如何给div加一个边框样式? 对div盒子加一个边框样式很简单只需要使用border板块样式即可. 一.虚线与实线边框 边框虚线样式:dashed 边框实现样式:solid border:1px da ...

  7. 一款基于TweenMax跟随鼠标单击移动的div

    今天给大家分享一款基于TweenMax跟随鼠标单击移动的div.在这款实例中你可以单击任意位置,div会移动到你单击的位置.效果图如下: 在线预览   源码下载 实现的代码. html代码: < ...

  8. CSS鼠标悬停图片加边框效果,页面布局发生错位的解决办法

    CSS鼠标悬停图片加边框效果,页面布局发生错位的解决办法 .recomend-list{ width:1200px; a{ @extend %fl; margin-right: 30px; width ...

  9. 【案例】鼠标按下,DIV跟随移动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. 【Python】Scrapy基础

    一.Scrapy 架构 Engine(引擎):负责 Spider(爬虫).Item Pipeline(管道).Downloader(下载器).Scheduler(调度器)中的通讯和数据传递. Sche ...

  2. bootstrap-editable实现bootstrap-table行内编辑

    bootstrap-editable行内编辑效果如下: 需要引入插件 列初始化代码,为可编辑的列添加editable属性: columns = [ { title: '文件名', field: 'Na ...

  3. python小游戏,石头/剪子/布

    #从控制台输入石头(1)/剪子(2)/布(3) player=int(input("玩家出拳 石头(1)/剪子(2)/布(3)")) #电脑随机出拳 computer comput ...

  4. 注册测绘师20180301-CNSS

    GNSS:Global Navigation Satellite System(全球卫星导航系统)GPS:Global Positioning System(全球定位系统)GPS是美国的卫星导航系统. ...

  5. Mysql 源码:关于innodb中两次写的探索

    转载自:http://www.cnblogs.com/bamboos/p/3553703.html?utm_source=tuicool&utm_medium=referral 两次写可以说是 ...

  6. Double H

    ##Double H Team 1.队员 王熙航211606379(队长) 李冠锐211606364 曾磊鑫211606350 戴俊涵211606359 聂寒冰211606324 杨艺勇2116063 ...

  7. FastReport导出PDF乱码的问题

    1.电脑查看乱码,替换文本控件,使用RichObject,而不使用TextObject 2.电脑查看正常,手机查看乱码,导出的时候选择包含字体: Enbeded Fonts勾选框

  8. python1-集合、函数-(全局变量与局部变量)

    集合 # s=set('hello')# print(s)## s=set(['alex','alex','sb'])# print(s) # s={1,2,3,4,5,6} #添加# s.add(' ...

  9. java 随机生成6位短信验证码

    生成6位随机数字其实很简单,只需一行代码,具体如下: String verifyCode = String.valueOf(new Random().nextInt(899999) + 100000) ...

  10. 初识html与css

    ---恢复内容开始--- PS应用量尺寸w.h- 操作方式: 窗口,信息,右上角面板选项,标尺单位,像素切图- 操作方式: 切片工具, 文件 ,另存为web所有格式,jpeg,存储,切片:选中的切片, ...