I need add scrollmagic.js whit requirejs on my project
My structure file is
/js
/app
main.js
/lib
debug.addIndicators.js
jquery.js
require.js
ScrollMagic.js
app.js
my app.js is
requirejs.config({
"baseUrl": "js/lib",
"paths": {
"app": "../app"
},
});
requirejs(["jquery"]);
requirejs(["app/main"]);
requirejs(["ScrollMagic"]);
requirejs(["debug.addIndicators"]);
in head script loading
<head>
<script data-main="js/app" src="js/lib/require.js"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="app" src="js/app.js"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="jquery" src="js/lib/jquery.js"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="app/main" src="js/lib/../app/main.js"></script>
<script type="text/javascript" charset="utf-8" async="" data-requirecontext="_" data-requiremodule="ScrollMagic" src="js/lib/ScrollMagic.js"></script>
</head>
my main.js is
define(['jquery'], function() {
jQuery(document).ready(function($) {
jQuery(function() { // wait for document ready
// init controller
var controller = new ScrollMagic.Controller({ loglevel: 3 });
// build scene
var scene = new ScrollMagic.Scene({ triggerElement: "#trigger", duration: 300, loglevel: 3 })
.setPin("#target")
.addIndicators() // add indicators (requires plugin)
.addTo(controller);
});
});
});
Into inspector I have this error and ScrollMagic not works
main.js:6 Uncaught ReferenceError: ScrollMagic is not defined
at HTMLDocument.<anonymous> (main.js:6)
at j (jquery.js:2)
at Object.fireWith [as resolveWith] (jquery.js:2)
at ready (jquery.js:2)
I also tried change define in main.js
define(['jquery','ScrollMagic','debug.addIndicators'], function() {
same error into inspector
You have to import ScrollMagic in your main.js like this:
define(['jquery', '/path/scrollmagic'], function(jQuery, ScrollMagic) {
....
....
});