CSS3动态在线客服
2021年06月18日
649
CSS3动态在线客服
案例知识点分析:
1、利用固定定位让外层容器出现在页面右下角。
2、使用after伪类设置右侧三角图标。
3、使用translate3d对元素进行水平、垂直居中显示。
4、利用animation动画,实现元素旋转和透明度的设置。

html:
<div class="consult_contact"> <div class="consult_wrap"> <a href=""> <div class="tip">hello,欢迎来咨询</div> <img src="img/ball.png" class="ball" alt=""> <img src="img/bg_0.png" class="staff_img" alt=""> <img src="img/bg_1.png" class="bg-1" alt=""> <img src="img/bg_2.png" class="bg-2" alt=""> <img src="img/bg_3.png" class="bg-3" alt=""> </a> </div> </div>
外层div定位显示在 页面右下角区域,css设置样式:
*{
font-size: 12px;
font-family: 'Microsoft YaHei';
}
.consult_contact{
width: 114px;
height: 114px;
cursor: pointer;
position: fixed;
bottom: 22%;
right: 0;
outline: 1px dashed red;
}预览:

把“hello,欢迎来咨询”的文本内容,放置在一个圆角矩形中,其中圆角矩形的左侧区域出现三角形,设置css样式,如下所示:
.consult_wrap .tip{
width: 150px;
height: 24px;
line-height: 24px;
border-radius: 3px;
font-size: 14px;
color: #fff;
text-align: center;
background: #3091f2;
position: absolute;
right: 95px;
top: 45px;
display: none;
-webkit-transition: display 1s ease;
transition: display 1s ease;
}
.consult_contact:hover .tip{
display: block;
}
.consult_wrap .tip::after{
content: '';
width: 0;
height: 0;
position: absolute;
right: -8px;
top: 50%;
border-top: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 4px solid #3091f2;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}预览:

接着,把所有的图片,定位在外层容器(类名叫.consult_contact的div)的的中间,设置css样式:
.consult_contact img{
width: auto;
position: absolute;
left: 50%;
top: 50%;
-webkit-transform: translate3d(-50%, -50%, 0);
transform: translate3d(-50%, -50%, 0);
}预览:

其中,深色的蓝色的圆,给其设置定位,让其向上移动20px。设置css样式:
.consult_contact .ball{
width: auto;
top: 20px;
z-index: 9999;
transform-origin: 0 38px;
animation: ballRotate 2.5s infinite linear;
}接着让这个深色的蓝色的圆,旋转360度。设置css样式:
@keyframes ballRotate {
0%{
transform: rotate(0);
}
100%{
transform: rotate(360deg);
}
}接着,给这个
<img src="img/bg_2.png" class="bg-2" alt="">
这个图片,设置css的透明度 的切换,切换的状态 在0 --- 1--- 0 之间进行透明度的切换,设置css样式:
.consult_contact .bg-2{
animation: bg2Animation 2.5s infinite linear;
}
@keyframes bg2Animation {
0%{
opacity: 0;
}
50%{
opacity: 1;
}
100%{
opacity: 0;
}
}总体预览效果如下所示:

