我正在尝试合并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);
}
});
答案 0 :(得分:0)
我能够通过以下方式将其导入。 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" />