700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 如何使用纯CSS实现一把剪刀的效果(附源码)

如何使用纯CSS实现一把剪刀的效果(附源码)

时间:2019-11-15 09:21:01

相关推荐

如何使用纯CSS实现一把剪刀的效果(附源码)

web前端|css教程

animation,transform,css,html5,前端

web前端-css教程

本篇文章给大家带来的内容是关于如何使用纯CSS实现一把剪刀的效果(附源码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

非绿平台源码,ubuntu18好吗,广州爬虫最多季节,php释放链接,seo 专业词lzw

效果预览

库存php源码,下vscode后重启变慢,ubuntu 硬盘 服务,多个tomcat版本下载,爬虫软件+地图,我叫mt php,seo营销推广关键词,克隆网站源码果6带,网页设计个人主页模板htmllzw

tp5.1网站源码,ubuntu 开机 紫屏,爬虫 淘宝月销量,现场PHP,南京seo讲师lzw

源代码下载

/comehope/front-end-daily-challenges

代码解读

定义 dom,容器中包含 2 个 .half 元素,各表示剪刀的半边,它的子元素 handle 表示刀柄,blade 表示刀,最后的 .joint 表示连接左右两部分铆钉:

居中显示:

body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center;}

定义容器尺寸,其中outline是辅助线:

.scissors { width: 21em; height: 7em; outline: 1px dashed;}

定义半边剪刀的尺寸,其中outline是辅助线:

.scissors { position: relative;}.half { position: absolute; width: inherit; height: 4em; outline: 1px dashed red;}

画出刀柄:

.handle { position: absolute; box-sizing: border-box; width: 8em; height: inherit; border: 1em solid #333; border-radius: 2em;}

画出刀,用圆角属性画出了顶部的刀尖:

.blade { position: absolute; width: 15em; height: 1em; background-color: silver; top: 3em; left: 6em; border-radius: 0 0 1em 0; z-index: -1;}

用伪元素在刀的底部画一个三角形,使刀与刀柄连接得更牢固:

.blade::before { content: \; position: absolute; border-style: solid; border-width: 0 1.8em 1em 1.8em; border-color: transparent transparent silver transparent; top: -1em; left: 0.2em;}

使半边刀倾斜:

.half { transform-origin: 45% bottom; transform: rotate(15deg);}

利用scale()函数画出剪刀的另一半:

.half { transform-origin: 45% bottom; transform: rotate(calc(15deg * var(--direction))) scaleY(var(--direction));}.half:nth-child(1) { --direction: 1; top: 0;}.half:nth-child(2) { --direction: -1; top: -1em;}

画出连接左右半边的铆钉:

.joint { position: absolute; width: 0.7em; height: 0.7em; background-color: #333; border-radius: 50%; top: calc(50% - 0.7em / 2); left: 45%;}

增加动画鼠标悬停时的动画效果:

.scissors:hover .half { animation: cut 2s ease-out;}@keyframes cut { 20%, 60% { transform: rotate(calc(30deg * var(--direction))) scaleY(var(--direction)); } 40%, 80% { transform: rotate(calc(5deg * var(--direction))) scaleY(var(--direction)); }}

最后,别忘了删掉辅助线。

大功告成!

如何使用纯CSS实现条纹错觉的动画效果(附源码)

如何使用css实现中国结的效果(代码)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。