web前端|css教程
前端,html5,css,css3,animation
web前端-css教程
本篇文章给大家带来的内容是关于如何使用纯CSS实现冰棍的动画效果(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
微信植入软文广告源码,vscode用svn,ubuntu与主机无法复制粘贴,tomcat 内存 99,qml+sqlite3,joomla插件大全,今年最流行的前端框架,阿斯达克爬虫,升级php5.6,seo团队价格,大气网络公司网站,网页页面如何切换效果,婚嫁模板,迭代算法matlab程序lzw
效果预览
android launcher源码,vscode手动添加cv2,ubuntu ide工具,双亲委派机制 tomcat,perl爬虫库,php读取大数据,seo搜索引擎优化招聘,网站后台忘记账号密码lzw
智慧学堂 源码,ubuntu com口设置,爬虫热力分析图,php 日志 保存,SEO内外链接lzw
源代码下载
/comehope/front-end-daily-challenges
代码解读
定义 dom,容器中包含 2 个元素:
居中显示:
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: darkslategray;}
绘制出冰棍的外形:
.flavors { width: 19em; height: 26em; font-size: 10px; border-radius: 8em 8em 1em 1em;}
给冰棍上色:
.flavors { position: relative; overflow: hidden;}.flavors::before { content: \; position: absolute; width: 140%; height: 120%; background: linear-gradient( hotpink 0%, hotpink 25%, deepskyblue 25%, deepskyblue 50%, gold 50%, gold 75%, lightgreen 75%, lightgreen 100%); z-index: -1; left: -20%; transform: rotate(-25deg);}
来一点光照效果:
.flavors::after { content: \; position: absolute; width: 2em; height: 17em; background-color: rgba(255, 255, 255, 0.5); left: 2em; bottom: 2em; border-radius: 1em;}
画出冰棍筷子:
.stick { position: relative; width: 6em; height: 8em; background-color: sandybrown; left: calc(50% - 6em / 2); border-radius: 0 0 3em 3em;}
给冰棍筷子加一点阴影,增加立体感:
.stick::after { content: \; position: absolute; width: inherit; height: 2.5em; background-color: sienna;}
让冰棍的色彩滚动起来:
.flavors::before { animation: moving 100s linear infinite;}@keyframes moving { to { background-position: 0 1000vh; }}
最后,增加交互效果,当鼠标悬停时才播放动画:
.flavors::before { animation-play-state: paused;}.ice-lolly:hover .flavors::before { animation-play-state: running;}
大功告成!
相关推荐:
如何使用纯CSS实现带有金属光泽的立体按钮的动画效果(附源码)
如何使用纯CSS实现文字断开的动画效果(附源码)
如何使用CSS实现渐变色动画边框的效果(附代码)