reactjs waypoint import issues

删除回忆录丶 提交于 2019-12-11 06:04:44

问题


I am trying to incorporate the jquery waypoints module. I am experiencing ALL of these issues in every attempt to use the module in reactjs.-- in this case I get an each of undefined - but I have tried to even use a local version of the lib and add to the top of the file

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

importing like this

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

code

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

回答1:


I was able to get this imported by the following. http://jsfiddle.net/Lfhepta3/7/

Import from a lib file.

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

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

At the top of the file - I've added the following line

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

-- then the usage I've used is this.

              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%'
              });

the div is like this

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


来源:https://stackoverflow.com/questions/56752469/reactjs-waypoint-import-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!