-webkit-clip-path:Firefox中的inset等效项

时间:2015-05-27 09:59:43

标签: css css3 firefox clip-path

简单问题 :我让这个clip-path maskChrome合作,想知道一种简单的方法来获得与Firefox相同的效果{1}}。

我做了一些研究,发现Firefox's clip-path适用于svg,但这是唯一的方法吗?在这种情况下如何动态更改mask

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)");
}

Here's it working with Chrome.

1 个答案:

答案 0 :(得分:0)

如果您关注的是浏览器支持,我建议对同一输出采用不同的方法:使用高度而不是clip-path

这将为(至少)chrome,Firefox,IE,safari,opera ......提供浏览器支持:

&#13;
&#13;
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 + "%");
}
&#13;
.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;
}
&#13;
<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');"/>
&#13;
&#13;
&#13;