I am trying to add custom js
to a single CMS page
in Magento 2.2.5.
Here is what I got:
I have put the rellax.min.js
file at :/app/design/frontend/TemplateMonster/md/web/js
And I want to use that js on my about us
CMS page so I invoked it like :
<script src="/app/design/frontend/TemplateMonster/md/web/js/rellax.min.js" type="text/javascript" xml="space"></script>
<script type="text/javascript" xml="space">// <![CDATA[
var rellax = new Rellax('.rellax');
// ]]></script>
<div class="content">
<div class="rellax slide1"></div>
<div class="rellax" data-rellax-speed="7">some text</div>
<div class="rellax slide2"></div>
<div class="rellax" data-rellax-speed="7">some text</div>
<div class="rellax slide3"></div>
</div>
The problem I am facing is that the js doesn't seem to affect the rellax
class like it is suppose to do.
Thanks for the help.
I have added rellax.js
in /public_html/app/design/frontend/TemplateMonster/md/web/js
Then requirejs-config.js
in this path
/public_html/app/design/frontend/TemplateMonster/md
with the following code
var config = {
map: {
'*': {
rellax: 'md/js/rellax'
}
},
shim: {
rellax: {
deps: ['jquery']
},
}
};
And this is the code in my CMS page
<script type="text/javascript" xml="space">// <![CDATA[
require([
'jquery',
'md/js/rellax'
], function ($, script) {
var rellax = new Rellax('.rellax');
alert('Here');
});
// ]]></script>
<div class="content">
<div class="rellax slide1"></div>
<div class="rellax" data-rellax-speed="7">some text</div>
<div class="rellax slide2"></div>
<div class="rellax" data-rellax-speed="7">some text</div>
<div class="rellax slide3"></div>
</div>