Last active
August 29, 2015 14:06
-
-
Save neoswf/02d66dadbfef56f0254c to your computer and use it in GitHub Desktop.
How to catch an error event for an SVG image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Image is a 87px height & 200px width long. | |
I'm calling an image from DB, but if it fails to load, im listening to the Error event, and than call an image from DB. | |
Big thing here is this guy: `onerror="this.href.baseVal='pathTo_placeholder_fallback_image'"` | |
`this.href.baseVal` | |
This guy enables you to overright the SVG image source, with the fallbacl one. | |
--> | |
<svg xmlns="http://www.w3.org/2000/svg" id="svgroot" viewBox="0 0 200 87" width="200" height="87"> | |
<defs> | |
<filter id="filtersPicture"> | |
<feComposite result="inputTo_38" in="SourceGraphic" in2="SourceGraphic" operator="arithmetic" k1="0" k2="1" k3="0" k4="0" /> | |
<feColorMatrix id="filter_38" type="saturate" values="0" data-filterid="38" /> | |
</filter> | |
</defs> | |
<image filter="url("#filtersPicture")" x="0" y="0" width="200" height="87" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="{{module_image}}" onerror="this.href.baseVal='{{ url_for('.static', filename='web/img/fallback/320x138.jpg') }}'" /> | |
</svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment