-webkit-clip-path: Firefox equivalent
A simple question . I got this clip-path mask
one working with Chrome
and would like to know an easy way to get the same effect using Firefox
.
I did some research and saw what Firefox's
clip-path
works with svg
, but is this the only way? How to dynamically change mask
in this case?
HTML:
<div id="image1" class="frame">
<div class="layer"></div>
<div class="layer"></div>
</div>
<input id="range1" type="range" value=0 max=100 oninput="UpdateImage('image1');"></input>
JavaScript:
function UpdateImage(id) {
image_elem = document.getElementById(id);
layers = image_elem.getElementsByClassName("layer");
range = document.getElementById("range1");
layers[1].setAttribute("style", "-webkit-clip-path:inset(" + range.value + "% 0 0 0)");
}
source to share
If your problem is with browser support, I would suggest a different approach for the same output: using height instead of clip-path
.
This will provide browser support (at least) chrome, Firefox, IE, safari, opera ...:
function UpdateImage(id) {
image_elem = document.getElementById(id);
layers = image_elem.getElementsByClassName("layer");
range = 100 - document.getElementById("range1").value;
layers[1].setAttribute("style", "height:" + range + "%");
}
.frame {
position:relative;
width: 375px;
height: 250px;
}
.frame .layer {
position:absolute;
bottom:0;
width: inherit;
height: inherit;
background-size: 100% auto;
background-position: left bottom;
}
#image1 .layer:nth-child(1) {
background-image:url("http://rlc.site90.net/images/img1_layer0.jpg");
}
#image1 .layer:nth-child(2) {
background-image:url("http://rlc.site90.net/images/img1_layer1.jpg");
}
#range1 {
width:375px;
}
<div id="image1" class="frame">
<div class="layer"></div>
<div class="layer"></div>
</div>
<input id="range1" type="range" value=0 max=100 oninput="UpdateImage('image1');"/>
source to share