简体   繁体   中英

Interactive SVG: Change Fill Color onMouseOver

I'm currently working on an imagemap in Addobe Illustrator CC and I want to be able to change the color of the shapes onMouseOver. Tried this in my SVG Interactivity panel:

style.fill="yellow" 

and it doesn't seem to work. What would be the proper function to place there for onMouseOver?

My onClick event to link out to websites does work. That was:

location.href='https://thecleverroot.com/tag/southwest/';

If you need to change only styling, then you can use CSS for SVG . Add class name to desired element and place the following code to your CSS file:

.className {
  color: yellow;
}

.className:hover {
  color: blue;
}

if you want to redirect users to another URL onClick, there is no need to use JavaScript. You can add anchor element to your SVG and place href there. Here is a nice article on this approach.

If you wish to style element while click use:

.className:active {
  color: red;
}

Use JavaScript only if your SVG should have some complex logic.

OK, I found a solution. Originally, Illustrator assigned fill styles to each shape in my group and not the group itself. Once I changed the fill references in my CSS to the ones in my group and not each individual path, I solved the problem and the hovers now work great without JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM