N
N
Nikita-Fast2018-09-29 15:57:40
JavaScript
Nikita-Fast, 2018-09-29 15:57:40

How to make hover effect cross browser?

We have (by me) an icon with a description of the function drawn in Inkscape.

How to make the fill of the text change when hovering over the gear itself, and also when hovering over the text, the fill of the gear changes?

https://jsfiddle.net/4eoybvnz/

ruSO sarcastic as usual...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
profesor08, 2018-09-29
@Nikita-Fast

No way with CSS, easy with js:

let icon = document.querySelector(".some-icon");
let text = icon.querySelector("text tspan");
let path = icon.querySelector("path");

text.addEventListener("mouseenter", function() {
  path.style.fill = "red";
});

text.addEventListener("mouseleave", function() {
  path.style.fill = "#626262";
});

path.addEventListener("mouseenter", function() {
  text.style.fill = "green";
});

path.addEventListener("mouseleave", function() {
  text.style.fill = "#626262";
});

A
Alexander Tsymbal, 2018-09-29
@AlexanderTsymbal

Still, it's not very elegant to write so much JS code when everything can be done with 3 lines of CSS.
The only amendment: I removed the inline styles from svg, transferred them to css. It's bad form to use inline styles for the svg that is part of the interactive web interface. Do as you wish.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question