【问题标题】:reactjs waypoint import issuesreactjs航点导入问题
【发布时间】:2019-06-25 10:55:26
【问题描述】:

我正在尝试合并 jquery waypoints 模块。在每次尝试在 reactjs 中使用模块时,我都遇到了所有这些问题。-在这种情况下,我得到了一个未定义的每个 - 但我什至尝试使用本地版本的 lib 并添加到文件的顶部

window.jQuery = window.$ = require("jquery");

http://imakewebthings.com/waypoints/guides/getting-started/
http://imakewebthings.com/waypoints/api/waypoint/
http://imakewebthings.com/waypoints/shortcuts/inview/

waypoint Uncaught TypeError: Cannot read property 'each' of undefined

Waypoint npm - Error: Can't resolve 'waypoint

in some instances - it errors -- "TypeError:`_libs_jquery_waypoints_js__WEBPACK_IMPORTED_MODULE_3___default.a is not a constructor"`

https://github.com/imakewebthings/waypoints/issues/559

这样导入

import Waypoint from './libs/jquery.waypoints.js';

代码

var ele
new Waypoint({
element: ele = $('.threesixty')[0],
handler: function(direction) {
if (direction == 'down') {
  $(ele).addClass('muestra')
} else {
  $(ele).removeClass('muestra')
}
  console.log(direction);
}
});

【问题讨论】:

  • 有没有一种普通的方式来做到这一点 - 使用常规 javascript --

标签: javascript reactjs jquery-waypoints


【解决方案1】:

我能够通过以下方式将其导入。 http://jsfiddle.net/Lfhepta3/7/

从 lib 文件导入。

import waypoint from './libs/jquery.waypoints.js';

https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.js

在文件的顶部 - 我添加了以下行

window.jQuery = window.$ = require("jquery");

-- 那么我用过的用法是这样的。

              var elem = "vision0";
              var $el = $('.'+elem);

              $el.waypoint(function(direction) {
                if (direction == 'down') {
                  $el.addClass("js-"+elem+"-animate");
                } else {
                  $el.removeClass("js-"+elem+"-animate");
                }
              }, {
                offset: '50%'
              });

div是这样的

      <img className="vision0" src={require(`img/${this.props.data.image}`)} width="900" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-28
    • 2021-12-24
    相关资源
    最近更新 更多