简体   繁体   English

Gatsby 中的 Snap.svg 缓动

[英]Snap.svg easing in Gatsby

How would I access mina from Snap.svg when using Gatsby?使用 Gatsby 时如何从Snap.svg访问mina

I can import the Snap object through import Snap from 'snapsvg' perfectly fine.我可以通过import Snap from 'snapsvg'完美地导入Snap对象。 But when I try to use mina or use import Snap, { mina } from 'snapsvg' it tells me that "mina is not defined."但是当我尝试使用mina或使用import Snap, { mina } from 'snapsvg'它告诉我“未定义 mina”。

My gatsby-node.js sets up my Webpack to allow import:我的gatsby-node.js设置了我的 Webpack 以允许导入:

exports.onCreateWebpackConfig = ({ stage, actions }) => {
    actions.setWebpackConfig({
        module: {
            rules: [
                {
                    test: require.resolve(
                        'snapsvg/dist/snap.svg.js'
                    ),
                    use:
                        'imports-loader?this=>window,fix=>module.exports=0',
                },
            ],
        },
        resolve: {
            alias: {
                snapsvg: 'snapsvg/dist/snap.svg.js',
            },
        },
    })
}

I would use Snap.svg-cjs or react-snap-svg but they seem to be pretty outdated.我会使用Snap.svg-cjsreact-snap-svg但它们似乎已经过时了。 Any solutions to allow access to mina or some other easing function for Snap.svg?任何允许访问mina或 Snap.svg 的其他缓动功能的解决方案?

I just did this today and came across your question before I'd worked it out.我今天刚做了这个,在我解决之前就遇到了你的问题。

The mina package just exports mathematical functions so you can pass your own, linear is the easiest: mina 包仅导出数学函数,因此您可以传递自己的函数,linear 是最简单的:

el.animate(
  { d: paths },
  5000,
  (n) => n, // linear function from mina
  () => {
    // callback stuff
  },
);

The rest you can find here: https://github.com/adobe-webplatform/Snap.svg/blob/master/src/mina.js#L241其余的你可以在这里找到: https : //github.com/adobe-webplatform/Snap.svg/blob/master/src/mina.js#L241

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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