css中clip属性是什么?clip:rect()制作圆形进度条动画(代码实例)

本章给大家带来css中clip属性是什么?clip:rect()制作圆形进度条动画(代码实例),给大家介绍了什么是clip属性,clip:rec()的用法,最后通过一个实例让大家更直观的了解clip:rect()。有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

一、css什么是clip属性?

clip 属性剪裁绝对定位元素。clip 属性允许定义一个元素的可见尺寸,当一幅图像的尺寸大于包含此元素时,此图像就会被修剪并显示为这个元素定义的形状。

1.语法

img {position:absolute;clip:rect(0px,60px,200px,0px);}

登录后复制

代码示例:

立即学习“前端免费学习笔记(深入)”;

nbsp;html>.demo{width: 200px;height: 500px;margin: 50px auto;}img{border: 1px solid #000;}.img {position:absolute;clip:rect(0px,165px,200px,34px);}

原图:

@@##@@

裁剪后

@@##@@

登录后复制

效果图:

css中clip属性是什么?clip:rect()制作圆形进度条动画(代码实例)

clip:rect(0px,165px,200px,34px)中的0px,165px,200px,34px分别对应图片的上,右,下,左四个方位 ;clip:rect()需要配合position属性使用,才能对图像进行裁剪。

注意:

如果先有”overflow:visible”定义了元素,clip属性就不起作用。

css中的clip:rect()只能在绝对定位的元素上使用,包括fixed属性的元素,因为fixed也算绝对定位

2.可用性隐藏

根据上面对top right bottom left的释义,如果left >= right或者bottom

二、css3制作圆形进度条动画(css3 动画与clip:rect()结合使用)

先看看加载效果图:

css中clip属性是什么?clip:rect()制作圆形进度条动画(代码实例)

代码实例:

nbsp;html>css3制作圆形进度条动画* {margin: 0;padding: 0;}body {overflow-x: hidden;overflow-y: scroll;font-family: MuseoSans, Georgia, "Times New Roman", Times, serif;font-size: 13px;color: #444;border-top: 3px solid #444;background-color: #E4E6E5;overflow-x: hidden;}section .demo {width: 530px;margin: 15em auto;overflow: hidden;}ul.notes {clear: both;}ul.notes li {float: left;margin-right: 3em;display: inline;}ul.notes li:last-child {margin: 0;}ul.notes li span.skill {display: block;text-align: center;padding: 10px 0;text-shadow: 1px 0 0 #FFFFFF;}.notesite {display: inline-block;position: relative;width: 1em;height: 1em;font-size: 5.4em;cursor: default;}.notesite>.percent {position: absolute;top: 20px;left: 0;width: 100%;font-size: 25px;text-align: center;z-index: 2;}.notesite>.percent .dec {font-size: 15px;}.notesite>#slice {position: absolute;width: 1em;height: 1em;clip: rect(0px, 1em, 1em, 0.5em);}.notesite>#slice.gt50 {clip: rect(auto, auto, auto, auto);}.notesite>#slice>.pie {position: absolute;border: 0.1em solid #444;width: 0.8em;height: 0.8em;-moz-border-radius: 0.5em;-webkit-border-radius: 0.5em;border-radius: 0.5em;-webkit-animation: craw 2s linear;-webkit-animation-iteration-count: 1;}@-webkit-keyframes craw {0% {clip: rect(0em, 1em, 0em, 0.5em);}50% {clip: rect(0em, 1em, 1em, 0.5em);-webkit-transform: rotate(0deg);-moz-transform: rotate(0deg);-ms-transform: rotate(0deg);-o-transform: rotate(0deg);transform: rotate(0deg);}100% {clip: rect(0em, 1em, 1em, 0em);-webkit-transform: rotate(90deg);-moz-transform: rotate(90deg);-ms-transform: rotate(90deg);-o-transform: rotate(90deg);transform: rotate(90deg);}}li.html .notesite>#slice>.pie {border-color: #DF6C4F;}.notesite.fill>.percent {display: none;}li.html .notesite:before {background: #DF6C4F;}
  • HTML

登录后复制

思路:

1.先画一个正方形边框

5.jpg

2. 通过border-radius属性使他变成一个圆 (考虑兼容性)

-moz-border-radius: 0.5em;-webkit-border-radius: 0.5em;border-radius: 0.5em;

登录后复制

1.jpg

3. 设置动画效果,通过改变clip的裁剪位置(与定位结合)使这个圆慢慢显现

@-webkit-keyframes craw {0% {clip: rect(0em, 1em, 0em, 0.5em);}50% {clip: rect(0em, 1em, 1em, 0.5em);-webkit-transform: rotate(0deg);-moz-transform: rotate(0deg);-ms-transform: rotate(0deg);-o-transform: rotate(0deg);transform: rotate(0deg);}100% {clip: rect(0em, 1em, 1em, 0em);-webkit-transform: rotate(90deg);-moz-transform: rotate(90deg);-ms-transform: rotate(90deg);-o-transform: rotate(90deg);transform: rotate(90deg);}}

登录后复制

2.jpg

3.jpg1.jpg

以上就是css中clip属性是什么?clip:rect()制作圆形进度条动画(代码实例)的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2891901.html

(0)
上一篇 2025年3月10日 22:19:23
下一篇 2025年3月6日 23:05:15

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论