react 中 加入script标签

2019-11-29  本文已影响0人  Fairy_zhao
componentDidMount () {
    const script = document.createElement("script");

    script.src = "https://use.typekit.net/foobar.js";
    script.async = true;

    document.body.appendChild(script);
}
//加入 点击栏目滑动到相应位置
      const script = document.createElement("script")
      script.text = `
        function scrollToAnchor (anchor, options) {
          if (anchor) {
            try {
              var el = document.getElementById(anchor)
              if (el) el.scrollIntoView(options)
            } catch (err) {
            }
          }
        }

        function maoScroll(anchor){
            scrollToAnchor(anchor.replace(/#/g, ''), { block: 'start', behavior: 'smooth', })
        }
      `
      document.body.appendChild(script)
上一篇 下一篇

猜你喜欢

热点阅读