html div 显示动画效果,66种基于animate.css的CSS消息提示动画效果

这是一款基于animate.css的效果非常酷的CSS消息提示动画效果。这66种CSS消息提示动画效果按出现位置分为4种类型:上部、中部、中下和右下。每个部位的消息提示效果都是不一样的。

注意:这个CSS消息提示动画效果需要在支持CSS3的浏览器中才能正常工作。

HTML结构

该CSS消息提示动画效果的HTML结构非常简单。使用一个id为#notifications的div作为整个包裹容器。

消息提示框的代码默认情况下是不存在与DOM中的,它们使用js来动态插入。例如当选择"Top"选项时,在点击触发按钮后,Top消息提示框将使用js插入到DOM中:

Oups something went wrong !

对于中部、中下和右下几个部位的消息提示框也是相同的操作。它们默认是不存在与DOM中的,只有在触发了相应的事件时,才使用jQuery来将HTML代码插入到DOM中的相应位置上。

...
avatar.png
delmarks sent you a message
...
avatar.png
delmarks sent you a message
...

CSS样式

该CSS消息提示动画效果有两个主要的CSS文件。一个是animate.css文件,用于产生各种动画效果。另一个是animated-notifications.css文件。在实际使用时,你需要在animate.css文件中查找你需要的class动画名称。下面是主要的消息提示框定位CSS代码:

#notifications-bottom-right {

position: absolute;

width: 360px;

right: 20px;

bottom: 20px;

}

#notifications-bottom-right-tab{

background-color: rgba(255,255,255,1);

float: left;

height: 100px;

width: 360px;

margin-top: 20px;

position: relative;

-moz-box-shadow: 0px 0px 10px rgba(0,0,0,0.1);

-webkit-box-shadow: 0px 0px 10px rgba(0,0,0,0.1);

box-shadow: 0px 0px 10px rgba(0,0,0,0.1);

}

#notifications-bottom-right-tab-close{

height: 20px;

width: 20px;

position: absolute;

top: 40px;

right: 20px;

color: #cccccc;

font-size: 18px;

line-height: 20px;

text-align: center;

-webkit-transition: all 0.5s;

-moz-transition: all 0.5s;

-o-transition: all 0.5s;

transition: all 0.5s;

}

#notifications-bottom-right-tab-close:hover {

color: rgba(102,102,102,1);

cursor: pointer;

}

#notifications-bottom-right-tab-avatar{

float: left;

height: 100px;

width: 70px;

margin-left: 20px;

}

#notifications-bottom-right-tab-avatar img{

-moz-border-radius: 50% 50% 50% 50%;

-webkit-border-radius: 50% 50% 50% 50%;

border-radius: 50% 50% 50% 50%;

-khtml-border-radius: 50% 50% 50% 50%;

float: left;

margin-top: 15px;

}

#notifications-bottom-right-tab-right{

float: left;

width: 210px;

margin-left: 20px;

margin-top: 20px;

}

#notifications-bottom-right-tab-right-title{

float: left;

width: 100%;

color: #252525;

font-weight: 600;

}

#notifications-bottom-right-tab-right-title span{

color: #e91e63;

}

#notifications-bottom-right-tab-right-text{

float: left;

width: 100%;

font-size: 14px;

color: #4c4c4c;

font-style: italic;

margin-top: 5px;

}

#notifications-bottom-center{

position: absolute;

width: 360px;

bottom: 90px;

left: 50%;

margin-left: -180px;

}

#notifications-bottom-center-tab{

background-color: rgba(255,255,255,1);

float: left;

height: 100px;

width: 360px;

margin-top: 20px;

position: relative;

-moz-box-shadow: 0px 0px 10px rgba(0,0,0,0.1);

-webkit-box-shadow: 0px 0px 10px rgba(0,0,0,0.1);

box-shadow: 0px 0px 10px rgba(0,0,0,0.1);

}

#notifications-bottom-center-tab-close{

height: 20px;

width: 20px;

position: absolute;

top: 40px;

right: 20px;

color: #cccccc;

font-size: 18px;

line-height: 20px;

text-align: center;

-webkit-transition: all 0.5s;

-moz-transition: all 0.5s;

-o-transition: all 0.5s;

transition: all 0.5s;

}

#notifications-bottom-center-tab-close:hover {

color: rgba(102,102,102,1);

cursor: pointer;

}

#notifications-bottom-center-tab-avatar{

float: left;

height: 100px;

width: 100px;

}

#notifications-bottom-center-tab-avatar img{

float: left;

}

#notifications-bottom-center-tab-right{

float: left;

width: 210px;

margin-left: 20px;

margin-top: 20px;

}

#notifications-bottom-center-tab-right-title{

float: left;

width: 100%;

color: #252525;

font-weight: 600;

}

#notifications-bottom-center-tab-right-title span{

color: #e91e63;

}

#notifications-bottom-center-tab-right-text{

float: left;

width: 100%;

font-size: 14px;

color: #4c4c4c;

font-style: italic;

margin-top: 5px;

}

#notifications-top-center {

position: fixed;

left: 0px;

top: 0px;

width: 100%;

background-color: rgba(255,255,255,1);

height: 50px;

text-align: center;

line-height: 50px;

color: #404040;

font-size: 18px;

font-weight: 600;

}

#notifications-top-center-close {

background-color: rgba(233,30,99,0.6);

float: right;

height: 50px;

width: 50px;

font-size: 30px;

color: rgba(255,255,255,1);

font-weight: 400;

-webkit-transition: all 0.5s;

-moz-transition: all 0.5s;

-o-transition: all 0.5s;

transition: all 0.5s;

}

#notifications-top-center-close:hover {

cursor: pointer;

background-color: rgba(233,30,99,1);

}

#notifications-full{

-moz-box-shadow: 0px 0px 50px rgba(0,0,0,0.1);

-webkit-box-shadow: 0px 0px 50px rgba(0,0,0,0.1);

box-shadow: 0px 0px 50px rgba(0,0,0,0.1);

height: 300px;

width: 530px;

background-color: rgba(255,255,255,1);

position: fixed;

margin-top: 10%;

margin-left: -265px;

z-index: 2;

left: 50%;

top: 10%;

}

#notifications-full-close{

height: 20px;

width: 20px;

position: absolute;

top: 10px;

right: 10px;

color: #cccccc;

font-size: 20px;

line-height: 20px;

text-align: center;

-webkit-transition: all 0.5s;

-moz-transition: all 0.5s;

-o-transition: all 0.5s;

transition: all 0.5s;

}

#notifications-full-close:hover {

color: rgba(102,102,102,1);

cursor: pointer;

}

#notifications-full-icon{

float: left;

width: 100%;

font-size: 65px;

text-align: center;

height: 65px;

margin-top: 35px;

color: #404040;

}

#notifications-full-text{

width: 430px;

float: left;

margin-left: 50px;

text-align: center;

margin-top: 40px;

font-size: 16px;

line-height: 24px;

color: #404040;

}

JAVASCRIPT

该CSS消息提示动画效果使用js代码使#notifications容器具有响应式效果,具体代码如下:

function resize(){

$('#notifications').height(window.innerHeight - 50);

}

$( window ).resize(function() {resize();});

resize();

每个消息提示框中都有一个关闭按钮,插件中使用一个函数来实现关闭功能:

function refresh_close(){

$('.close').click(function(){$(this).parent().fadeOut(200);});

}

refresh_close();

每个部位的消息提示框的HTML代码都是在JS文件中动态添加的。例如上部的HTML结构代码如下:

var top = '

Oups something went wrong !
';

最后是在选择了相应的动画效果后,点击提交按钮时将各种效果的消息提示框插入到DOM中。当#notifications-window-row-button按钮被点击时,插件会检测当前选择的位置和动画效果,然后移除旧的内容,在将新的内容添加到DOM中。在添加了新的内容之后,再使用refresh_close()函数来使消息提示框的关闭按钮可用。上部和中部的消息提示框是插入在#notifications中,而中下和右下部位的消息提示框是分别插入到#notifications-bottom-center和#notifications-bottom-right中,注意这点区别。

$('#notifications-window-row-button').click(function(){

if($('#position').val()=='top'){

$("#notifications-top-center").remove();

$("#notifications").append(top);

$("#notifications-top-center").addClass('animated ' + $('#effects').val());

refresh_close();

}

if($('#position').val()=='center'){

$("#notifications-full").remove();

$("#notifications").append(center);

$("#notifications-full").addClass('animated ' + $('#effects').val());

refresh_close();

}

if($('#position').val()=='bottom'){

$("#notifications-bottom-center").html();

$("#notifications-bottom-center").html(bottom);

$("#notifications-bottom-center-tab").addClass('animated ' + $('#effects').val());

refresh_close();

}

if($('#position').val()=='botom_right'){

$("#notifications-bottom-right").html();

$("#notifications-bottom-right").html(bottom_center);

$("#notifications-bottom-right-tab").addClass('animated ' + $('#effects').val());

refresh_close();

}

});

});

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里给你提供一种使用自定义类名和animate.css动画库给一张图片添加入场动画的示例。使用animate.css可以方便地实现CSS动画效果,具体可以根据需求自定义。 首先,需要在HTML文件中引入animate.css的CDN链接: ```html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> ``` 然后,HTML代码如下: ```html <div class="image-wrapper animate__animated"> <img src="image.jpg" alt="图片"> </div> ``` CSS代码如下: ```css .image-wrapper { position: relative; display: inline-block; } .image-wrapper.animate__animated { animation-duration: 1s; /* 设置动画持续时间 */ animation-delay: 0.5s; /* 设置动画延迟时间 */ animation-fill-mode: both; /* 设置动画结束后保持最后状态 */ animation-name: slideInLeft; /* 设置动画名称 */ } @keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } } .image-wrapper img { display: block; max-width: 100%; height: auto; } ``` 这段代码使用了animate.css库中的slideInLeft动画效果,通过给`.image-wrapper`添加类名`.animate__animated`来触发动画效果。其中,`.image-wrapper.animate__animated`使用了CSS3的动画属性animation,通过设置animation-duration、animation-delay、animation-fill-mode、animation-name属性来定义动画效果。同时,利用@keyframes定义了从左侧平移进入的动画效果。最后,`.image-wrapper img`设置了图片的基本样式,其中max-width: 100%可以确保图片的宽度不会超出其容器的宽度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值