简体   繁体   English

如何在不中断的情况下在SVG中变换对象?

[英]How to transform an object in SVG without cutting off?

I'm trying to apply transformation for image in the SVG instead IMG in the div. 我正在尝试将转换应用于SVG中的图像,而不是div中的IMG。 How to transform an object in SVG without cutting off? 如何在不中断的情况下在SVG中变换对象? Check the example and hover above images, I need effect for SVG the same as right div 检查示例并将鼠标悬停在上面的图像上,我需要对SVG效果与右div相同

 .container { display: flex; width: 200px; justify-content: space-around; } .asSvg image{ transition: transform 0.5s; cursor: pointer; } .asSvg image:hover { transform: translateX(-10px); } .chip { transform: rotate(-34deg); display: inline-block; overflow: hidden; cursor: pointer; } .chip img { transform: rotate(34deg) translate3d(7px, 0 ,0); transition: transform 0.5s; } .chip img:hover { transform: rotate(34deg) translate3d(0, 0 ,0); } 
 <div class="container"> <svg class="asSvg" width="60" height="60" viewBox="0 0 60 60"> <defs> <clipPath id='clipping'> <path d='M0,0 L0,0 L35,0 L60,26 L60,60 L0,60'/> </clipPath> </defs> <g clip-path='url(#clipping)'> <image xlink:href='https://s11.postimg.org/vzvfu6osz/chip_25.png' width="60" height="60"/> </g> </svg> <div class="chip"> <img src="https://s11.postimg.org/vzvfu6osz/chip_25.png"> </div> </div> 

The solution is to give more space to the svg width and the path element. 解决方案是给svg宽度和path元素更多的空间。 So when you hover the image, the path won't block or cut off the image. 因此,当您将鼠标悬停在图像上时,路径不会阻塞或剪切图像。 Check the updated demo to see my changes. 检查更新的演示以查看我的更改。

 .container { display: flex; width: 200px; justify-content: space-around; } .asSvg image{ transition: transform 0.5s; cursor: pointer; } .asSvg image:hover { transform: translateX(-10px); } .chip { transform: rotate(-34deg); display: inline-block; overflow: hidden; cursor: pointer; } .chip img { transform: rotate(34deg) translate3d(7px, 0 ,0); transition: transform 0.5s; } .chip img:hover { transform: rotate(34deg) translate3d(0, 0 ,0); } 
 <div class="container"> <!-- edit svg width to 90 --> <svg class="asSvg" width="90" height="60" viewBox="0 0 60 60"> <defs> <clipPath id='clipping'> <!-- edit the path width to -30, this will give additional 30px to the path element --> <path d='M-30,0 L0,0 L35,0 L60,26 L60,60 L0,60'/> </clipPath> </defs> <g clip-path='url(#clipping)'> <image xlink:href='https://s11.postimg.org/vzvfu6osz/chip_25.png' width="60" height="60"/> </g> </svg> <div class="chip"> <img src="https://s11.postimg.org/vzvfu6osz/chip_25.png"> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM