How do I change the clip path using javascript?
I want to change a clip of an image using javascript (no jquery), but it seems that I am not doing it right.
Here's the fiddle - https://jsfiddle.net/y4j7bLge/1/
css:
clip-path: inset(20px 20px 20px 20px); // works
javascript:
el.style.clipPath = "inset(60px 60px 60px 60px);" // doesn't work
+3
source to share
1 answer
Remove the ;
values ββat the end.
el.style.clipPath = "inset(60px 60px 60px 60px)"
// here ------^^-----
var el = document.getElementById("someImg")
// doesn't work
el.style.clipPath = "inset(60px 60px 60px 60px);"
#someImg {
width: 332px;
height: 300px;
background-image: url(https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg);
clip-path: inset(20px 20px 20px 20px);
}
<div id="someImg" width="332px" height="300px">
</div>
+4
source to share