php - Is there a workaround for SVGs and filters not working Safari ← (PHP, JavaScript, CSS, HTML)
one text
I've been looking around for a while, and it seems to be pretty well recognized that Safari has some problems applying filters to SVGs. I haven't seen many solutions though, and the few I have come across don't seem relevant to what I'm doing. I'm hoping someone can offer a solution or workaround for what I'm trying to accomplish.
I'm building a game with tiles (think, Settlers of Catan) and I'm using SVG polygons to do it. The polygons are usually blank and have some sort of text in them, but for a few they have an image (fill
) in them. The polygons with text seem to work fine and it is only the images that have problems. There are at least two instances when I apply filters to the polygons: hovering with your mouse, and when a tile is controlled by a player. In these instances the image in the polygon simply disappears.
I am using javascript to apply a CSS class that references an SVG definition in the same file as the polygon. This all works fine in Chrome.
Is there a way to fix this, or at the very least to work around this in Safari?
PHP/HTML
<svg>
<def>
<pattern id="someImage" patternUnits="objectBoundingBox" x="0" y="0" width="1" height="1">
<image xlink:href="https://website.com/images/something.png" x="0" y="0" width="1" height="1"></image>
</pattern>
<filter id="hover" x="0" y="0">
<feColorMatrix in="SourceGraphic" type="matrix" values=" 0 1 0 0 .66 0 1 0 0 .66 0 1 0 0 .66 0 1 0 1 0 "></feColorMatrix>
</filter>
<filter id="red" x="0" y="0">
<feColorMatrix in="SourceGraphic" type="matrix" values=" 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 1 0 "></feColorMatrix>
</filter>
</def>
<g>
<polygon points="25,43 20,51 10,51 5,43 9,34 20,34" class="tileBackground redImage" fill="url(#someImage)”></polygon>
</g>
</svg>
CSS
.tile:hover .tileBackground {
filter: url(#hover);
}
.red {
fill: red;
}
.redImage {
filter: url(#red);
}
Image from Chrome
Image from Safari
I think I included all the relevant code; let me know if something else would be useful.
Source
See also:
About the technologies asked in this question PHP PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.https://www.php.net/
JavaScript JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.https://www.javascript.com/
CSS CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.https://www.w3.org/TR/CSS/#css
HTML HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.https://www.w3.org/html/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.