clip:rect矩形剪裁
clip:rect(top right bottom left);依据上-右-下-左的顺序提供自图片左上角为(0,0)坐标计算的四个偏移数值,其中任一数值都可用auto替换.
矩形剪裁 还需要绝对定位position:absolute;这个clip有点像background-position这个属性,经常用css雪碧图都会知道。
下面就把我测试的代码方式:不能保证每张图片大小都一样,写的一个小方法,让裁切居中吧!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <! DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < title >Document</ title > </ head > < style > *{margin: 0;padding: 0;} .a{ width: 2px;height: 300px; background: #000; position: absolute;z-index: 2 } .b{ position: absolute;z-index: 3; height: 2px;width: 600px; background: #000; } </ style > < script src="jquery-1.11.1.min.js"></ script > < body > < img id="i" src="01.jpg" alt="" width= "300 " height= "300 " style="position: absolute;top:0;left:0;"> < div class="a"></ div > < div class="b"></ div > < script > var h=$("#i").outerHeight(); var w=$("#i").outerWidth(); var box=100; $(".a").css("margin-left",w/2) $(".b").css("margin-top",h/2) var h1=(h/2)-box, w1=(w/2)+box, h2=(h/2)+box, w2=(w/2)-box; $("#i").css("clip","rect("+h1+"px,"+w1+"px,"+h2+"px,"+w2+"px)"); </ script > </ body > |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· 对象命名为何需要避免'-er'和'-or'后缀
· JDK 24 发布,新特性解读!
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· SQL Server如何跟踪自动统计信息更新?