Custom javascript not working
The past tense for the quoting particle って
Why doesn't "adolescent" take any articles in "listen to adolescent agonising"?
Rationale to prefer local variables over instance variables?
How spaceships determine each other's mass in space?
Did Amazon pay $0 in taxes last year?
Are Wave equations equivalent to Maxwell equations in free space?
Learning to quickly identify valid fingering for piano?
The Key to the Door
Align equations with text before one of them
How can I be pwned if I'm not registered on the compromised site?
The need of reserving one's ability in job interviews
When to use the term transposed instead of modulation?
A bug in Excel? Conditional formatting for marking duplicates also highlights unique value
If nine coins are tossed, what is the probability that the number of heads is even?
What is "desert glass" and what does it do to the PCs?
Dukha vs legitimate need
Professor forcing me to attend a conference
Should I use HTTPS on a domain that will only be used for redirection?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
What is a term for a function that when called repeatedly, has the same effect as calling once?
Why can't we use freedom of speech and expression to incite people to rebel against government in India?
What is the purpose of a disclaimer like "this is not legal advice"?
Convert an array of objects to array of the objects' values
Has a sovereign Communist government ever run, and conceded loss, on a fair election?
Custom javascript not working
I'm trying to inject a scroll to anchor javascript globally in Magento 2.
More specifically this script:
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
Taken from this blog post.
I converted it to include defines and stuff:
define([
"jquery",
"jquery/ui"
], function ($) {
'use strict';
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
});
And injecting it in my themes default_head_blocks.xml
with <link src="js/custom.js" />
The injection works but I get the following error in Chrome console:
Uncaught Error: Mismatched anonymous define() module: function ($) {
'use strict';
require.js:166
What is wrong?
magento2 javascript requirejs
add a comment |
I'm trying to inject a scroll to anchor javascript globally in Magento 2.
More specifically this script:
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
Taken from this blog post.
I converted it to include defines and stuff:
define([
"jquery",
"jquery/ui"
], function ($) {
'use strict';
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
});
And injecting it in my themes default_head_blocks.xml
with <link src="js/custom.js" />
The injection works but I get the following error in Chrome console:
Uncaught Error: Mismatched anonymous define() module: function ($) {
'use strict';
require.js:166
What is wrong?
magento2 javascript requirejs
add a comment |
I'm trying to inject a scroll to anchor javascript globally in Magento 2.
More specifically this script:
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
Taken from this blog post.
I converted it to include defines and stuff:
define([
"jquery",
"jquery/ui"
], function ($) {
'use strict';
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
});
And injecting it in my themes default_head_blocks.xml
with <link src="js/custom.js" />
The injection works but I get the following error in Chrome console:
Uncaught Error: Mismatched anonymous define() module: function ($) {
'use strict';
require.js:166
What is wrong?
magento2 javascript requirejs
I'm trying to inject a scroll to anchor javascript globally in Magento 2.
More specifically this script:
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
Taken from this blog post.
I converted it to include defines and stuff:
define([
"jquery",
"jquery/ui"
], function ($) {
'use strict';
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
});
And injecting it in my themes default_head_blocks.xml
with <link src="js/custom.js" />
The injection works but I get the following error in Chrome console:
Uncaught Error: Mismatched anonymous define() module: function ($) {
'use strict';
require.js:166
What is wrong?
magento2 javascript requirejs
magento2 javascript requirejs
asked 1 min ago
JohnJohn
1063
1063
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264940%2fcustom-javascript-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264940%2fcustom-javascript-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown