纯CSS实现通知公告滚动效果
Admin 2021-04-16 群英技术资讯 1412 次浏览
HTML部分
<div class="notice"> <div class="notice__inner"> <div class="notice__box"> <div class="notice__item">恭喜会员用户 <span style="color: red;">橙某人</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">小密圈圈</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">Cooke_</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">爱音乐网站</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">青年之声</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">仙人</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">三十万人编号</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">Maboroshii</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">陈亚明</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">老娘终于发达了</span> 中奖</div> </div> <div class="notice__box"> <div class="notice__item">恭喜会员用户 <span style="color: red;">橙某人</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">小密圈圈</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">Cooke_</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">爱音乐网站</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">青年之声</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">仙人</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">三十万人编号</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">Maboroshii</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">陈亚明</span> 中奖</div> <div class="notice__item">恭喜会员用户 <span style="color: red;">老娘终于发达了</span> 中奖</div> </div> </div> </div>
CSS部分
.notice{ width: 300px; height: 300px; border-radius: 8px; border: 1px solid #eee; margin: 100px auto; } .notice__inner{ width: 100%; height: 100%; overflow: hidden; font-size: 14px; color: #666; } .notice__box{ animation: roll 10s linear infinite; } .notice__item{ width: 100%; height: 30px; line-height: 30px; padding: 0 12px; white-space: nowrap; } @keyframes roll { 0% { transform: translateY(0); } 100% { transform: translateY(-300px); } }
HTML部分
<div class="notice"> <div class="notice__inner"> <div class="notice__item">HTTP升级HTTPS全过程,Nginx配置平滑升级</div> <div class="notice__item">一台电脑存在多个版本的Vuecli,方便快速初始化不同版本的Vue项目</div> <div class="notice__item">前端模块化规范定义-不同规范下的导入导出</div> <div class="notice__item">快速、简洁讲明Vue中v-for循环key的作用</div> <div class="notice__item">Call与Apply函数的分析及手写实现</div> <div class="notice__item">普通切图仔的一年 | 掘金年度征文</div> <div class="notice__item">前端需要了解的浏览器缓存(即HTTP缓存)| 技术专题第八期征文</div> </div> </div>
CSS部分
.notice{ width: 600px; height: 40px; border-radius: 8px; border: 1px solid #eee; margin: 100px auto; overflow: hidden; } .notice__inner{ animation: roll 36s linear infinite; margin-top: 0 } .notice__item{ font-size: 14px; height: 40px; line-height: 40px; padding: 0 12px; white-space: nowrap; text-decoration: underline; } @keyframes roll { 0% { margin-top: 0; } 4% { margin-top: 0; } 8% { margin-top: 0; } 12% { margin-top: -40px; } 16% { margin-top: -40px; } 20% { margin-top: -80px; } 24% { margin-top: -80px; } 28% { margin-top: -120px; } 32% { margin-top: -120px; } 36% { margin-top: -160px; } 40% { margin-top: -160px; } 44% { margin-top: -200px; } 48% { margin-top: -200px; } 52% { margin-top: -240px; } 56% { margin-top: -240px; } 60% { margin-top: -200px; } 64% { margin-top: -200px; } 68% { margin-top: -160px; } 72% { margin-top: -160px; } 76% { margin-top: -120px; } 80% { margin-top: -120px; } 84% { margin-top: -80px; } 88% { margin-top: -80px; } 92% { margin-top: -40px; } 96% { margin-top: -40px; } 100% { margin-top: 0; } }
(gif录制可能稍微短了一点,建议动手试试看哦)
这种轮播的形式是比较常见的一种,也是比较实用完善简单的一种,随便提一句在微信小程序上用swiper组件去实现比较简单快捷
HTML部分
<div class="notice"> <div class="notice__inner"> <span class="notice__item notice__item-first">Vue是一个渐进式的 JavaScript 框架</span> <span class="notice__item notice__item-second">Vue是一个渐进式的 JavaScript 框架</span> </div> </div>
CSS部分
.notice{ width: 600px; height: 40px; border-radius: 8px; border: 1px solid #eee; margin: 100px auto; overflow: hidden; } .notice__inner{ height: 100%; font-size: 14px; color: #333; line-height: 40px; white-space: nowrap; position: relative; } .notice__item{ position: absolute; top: 0; left: 100%; height: 100%; } .notice__item-first{ padding-right: 70%; animation: rollFirst 25s linear infinite; } .notice__item-second{ padding-right: 53%; animation: rollSecond 25s linear 12s infinite; } @keyframes rollFirst { 0% { transform: translateX(0); } 100% { transform: translateX(-200%); } } @keyframes rollSecond { 0% { transform: translateX(0); } 100% { transform: translateX(-200%); } }
这种滚动通知栏也是比较常见的一种,它比较麻烦的一点就是那个空白间隔不好控制,特别在多个通知内容的时候,当然用JS还是比较好实现的,现在也有很插件可以直接开箱就用啦。
以上就是用纯css实现的通知公告滚动效果,虽然我们使用纯HTML+CSS代码不如JS那么灵活,但是对大家学习和掌握CSS动画和快速实现交互效果都是很有用处的,希望大家看完上述内容有所收获。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
css中能把cursor变成抓手样的形状,注意不是超链接的那种手,是抓手css:{cursor:url('绝对路径的图片(格式:cur,ico)'),-moz-zoom-out;}//FF下面css:{cursor:url('绝对路径'),auto;}//IE,FF,chrome浏览器都可以例子代码如下复制代码.style1{cursor:url('http://你地网站/手抓.jpg');}补充:问题一浏览器不兼容问题:在FF火狐 ...
这篇文章主要介绍了如何为 Element UI 里的 autosize textarea 设置高度,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
这篇文章主要介绍了详解flex布局中保持内容不超出容器的解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
在编写 CSS 时,有时可能会使用很长的选择器列表来定位具有相同样式规则的多个元素。例如,如果您想对标题中的 b 标签进行颜色调整,我们应该都写过这样的代码: h1 > b, h2 > b, h3 > b, h4 > b, h5 >...
一、CSSSprites简介通常被意译为“CSS图像拼合”或“CSS贴图定位”。CSSSprites并不是一门新技术,目前它已经在网页开发中发展得较为成熟,CSSSprites并不是什么金科玉律,但在很多情况下,它有着一定的优势,最重要的是它可以减轻服务器的负载,提高网页加载速度。CSSSprites允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008