javascript - Remove clipPath on hover -
in short have image masked using clippath
works in ie 9+. issue need have mask hide on hover reveals full image, reapply on mouseout. script have right not work. pen included below. new svg , clippath
.
http://codepen.io/omgdracula/pen/ejpzqx
$(document).ready(function() { $('.finish') .mouseover(function() { $(this).find('svg').find('clippath').css('display', 'none'); }).mouseout(function() { $(this).find('svg').find('clippath').css('display', 'block'); }); })
<div class="col-xs-3 finish" style="position:relative;border:1px solid red;"> <img src="http://placehold.it/297x252" class="img-responsive" /> <svg preserveaspectratio="xmidymin slice" style="width:100%;height:252px;top:0;left:0;position:absolute;border:dotted 2px blue" version="1.1" xmlns="http://www.w3.org/2000/svg" width="297" height="252" x="0px" y="0px" style="enable-background:new 0 0 297 252;" viewbox="0 0 297 252" xml:space="preserve"> <defs> <clippath id="maskid0"> <rect width="100%" height="252" x="0" y="0" /> </clippath> </defs> <title>test image</title> <desc>test 123</desc> <image clip-path="url(#maskid0)" width="297" height="252" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://placehold.it/297x252"></image> </svg> </div>
changing display
property of clippath
element has no effect because clippath
definition , doesn't have display of own. image
gets displayed after being clipped defined clippath
. so, simple solution remove clip-path
attribute on mouse-in , add (along original clip path url) again on mouse-out.
$(document).ready(function() { $('.finish').mouseover(function() { $(this).find('svg image').removeattr('clip-path'); }).mouseout(function() { $(this).find('svg image').attr('clip-path', 'url(#maskid0)'); }); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="col-xs-3 finish" style="position:relative;border:1px solid red;"> <img src="http://placehold.it/297x252" class="img-responsive" /> <svg preserveaspectratio="xmidymin slice" style="width:100%;height:252px;top:0;left:0;position:absolute;border:dotted 2px blue" version="1.1" xmlns="http://www.w3.org/2000/svg" width="297" height="252" x="0px" y="0px" style="enable-background:new 0 0 297 252;" viewbox="0 0 297 252" xml:space="preserve"> <defs> <clippath id="maskid0"> <rect width="150" height="252" x="0" y="0" /> </clippath> </defs> <title>test image</title> <desc>test 123</desc> <image clip-path="url(#maskid0)" width="297" height="252" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://placehold.it/297x252"></image> </svg> </div>
Comments
Post a Comment