如何使用 Snap SVG 创建鼠标悬停动画? [英] How do I create a mouseover animation using Snap SVG?

查看:23
本文介绍了如何使用 Snap SVG 创建鼠标悬停动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Snap.svg 创建悬停地图动画,但动画部分似乎有问题.该地图在 Illustrator 中创建并导出为 SVG 文件,并链接到 HTML 页面.

I am creating a hover map animation using Snap.svg, but I seem to be having problems with the animation portion. The map was created in Illustrator and exported as an SVG file and is linked to an HTML page.

一旦我添加了下面的代码,一切都消失了.

Once I add the code below, everything disappears.

veryCold.mouseover(function() {
    this.animate({
        fill: "#ff0000"
    }, 600);
}).mouseout(function() {
    this.animate({
        fill: "#bada55"
    }, 200);

我是 Stack Overflow 的新手,所以如果您需要任何其他信息,请告诉我.您可以提供的任何帮助将不胜感激.谢谢!

I am new to Stack Overflow, so please let me know if you need any additional information. Any help you can provide will be greatly appreciated. Thank you!

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Snap.svg</title>
        <style>
        body {
            background: #333;   
            }
        </style>
        <script src="Snap.svg-0.4.1/dist/snap.svg.js"></script>
        <script src="Snap.svg-0.4.1/dist/snap-min.svg.js"></script>
    </head>
    <body>
        <svg width="0" height="0">

        </svg>
        <script>
            var s = Snap(1080, 700);

            Snap.load("BuildingAmerica_ClimateMap_Vector-CJ-20150129-Buttons.svg", function(f) {
                var g = f.selectAll("g"),
                    wra = f.selectAll("path[class='st0']").attr({display: "none",}),
                    wrb = f.selectAll("path[class='st1']").attr({display: "inline", fill: "#FFFFFF"}),
                    wrc = f.selectAll("path[class='st2']").attr({"opacity": 0.75}),
                    wrd = f.selectAll("path[class='st3']").attr({fill: "#63B1C0"}),
                    wre = f.selectAll("path[class='st4']").attr({"opacity": 0, fill: "#63B1C0"}),
                    wrf = f.selectAll("path[class='st5']").attr({fill: "#C97F4C"}),
                    wrg = f.selectAll("path[class='st6']").attr({fill: "#B25415"}),
                    wrh = f.selectAll("path[class='st7']").attr({fill: "#C87D4B"}),
                    wri = f.selectAll("path[class='st8']").attr({"opacity": 0, fill: "#C97F4C"}),
                    wrj = f.selectAll("path[class='st9']").attr({fill: "#8CB533"}),
                    wrk = f.selectAll("path[class='st10']").attr({"opacity": 0, fill: "#8CB533"}),
                    wrl = f.selectAll("path[class='st11']").attr({fill: "#EEA135"}),
                    wrm = f.selectAll("path[class='st12']").attr({"opacity": 0, fill: "#EEA135"}),
                    wrn = f.selectAll("path[class='st13']").attr({fill: "#6D7CBC"}),
                    wro = f.selectAll("path[class='st14']").attr({fill: "#323E96"}),
                    wrp = f.selectAll("path[class='st15']").attr({fill: "#333B97"}),
                    wrq = f.selectAll("path[class='st16']").attr({"opacity": 0, fill:"#6D7CBC"}),
                    wrr = f.selectAll("path[class='st17']").attr({fill: "none", stroke: "#FFFFFF", strokeWidth: 0.2709}),
                    wrs = f.selectAll("path[class='st18']").attr({fill: "none", stroke: "#000000", strokeWidth: 0.4});

                s.append(g);
                s.append(wrb);
                s.append(wra);
                s.append(wrc);

                var veryCold = s.group(wrn, wro, wrp, wrq);
                veryCold.mouseover(function() {
                    this.animate({
                        fill: "#ff0000"
                        }, 600);
                    }).mouseout(function() {
                    this.animate({
                        fill: "#bada55"
                        }, 200);

                var mixedHumid = s.group(wrj, wrk);
                var hotHumid = s.group(wrl, wrm);
                var hotDry = s.group(wrf, wrg, wrh, wri);
                var marine = s.group(wrd, wre);

                s.append(wrr);
                s.append(wrs);
            });
        </script>
      </body>
</html>

推荐答案

veryCold.mouseover(function() {
    this.animate({
        fill: "#ff0000"
    }, 600);
}).mouseout(function() {
    this.animate({
        fill: "#bada55"
    }, 200);
}); // <--- It looks like you're missing this line

从您分享的内容来看,您的代码格式不正确.

From what you've shared it looks like your code isn't properly formatted.

这篇关于如何使用 Snap SVG 创建鼠标悬停动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆