Javascript, passing my string as an argument turns it to a 0





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm using scrollmagic.io and am making an anchor navigation menu. I'm following this tutorial. The scroll works! Except it was scrolling back to the beginning and not to the page it should be at.



Here is my code:



// init controller
var controller = new ScrollMagic.Controller();

// animate scroll instead of a jump
controller.scrollTo(function(target) {
console.log('scroooooll');
console.log('target = '+target); // THIS IS PRINTING 0
console.log(typeof(target));
/* Commenting out what it should do for simplicity. */
});

// scroll action when you click the nav links
$(document).on('click', 'a[href^=#]', function(e) {
var id = $(this).attr('href'); // get the href of clicked link
if ($(id).length > 0) { // not empty links
e.preventDefault(); // prevent normal link action

// this is the function call
console.log('click');
console.log('id = '+id); // IT PRINTS CORRECT HERE
console.log(typeof(id));
controller.scrollTo(id); // scroll on click

// update the URL
if (window.history && window.history.pushState) {
history.pushState("", document.title, id);
}
}
});


And here is the output of my console log:



click
id = #{the-href-value}
string
scroooooll
target = 0
number


My Javascript is pretty rusty, but this doesn't seem right to me. Why is it changing my variable from a string to a 0 when I pass it as a parameter?










share|improve this question























  • Have you tried debugging it in the browser?

    – Olian04
    Nov 16 '18 at 23:08











  • I am using my browser. The output is what the console log prints when I click the link. I'm trying to figure out where the 0 comes from.

    – Clara Olson
    Nov 16 '18 at 23:09













  • I'm talking about using the debugger, not just console.log. For example the chrome debugger.

    – Olian04
    Nov 16 '18 at 23:10






  • 1





    The first time you call controller.scrollTo you're passing it a function, the second time just an id. I don't know which one is right, but I imagine that's the reason for the discrepancy.

    – Jonny Rathbone
    Nov 16 '18 at 23:10











  • The way i understand it, it's supposed to be the scroll position of the target element. so it's supposed to be a number. 0 to me means you're giving it an id that doesn't match up with an element on the page, or the plugin is unable to get a y position for said element for whatever reason.

    – Kevin B
    Nov 16 '18 at 23:11




















0















I'm using scrollmagic.io and am making an anchor navigation menu. I'm following this tutorial. The scroll works! Except it was scrolling back to the beginning and not to the page it should be at.



Here is my code:



// init controller
var controller = new ScrollMagic.Controller();

// animate scroll instead of a jump
controller.scrollTo(function(target) {
console.log('scroooooll');
console.log('target = '+target); // THIS IS PRINTING 0
console.log(typeof(target));
/* Commenting out what it should do for simplicity. */
});

// scroll action when you click the nav links
$(document).on('click', 'a[href^=#]', function(e) {
var id = $(this).attr('href'); // get the href of clicked link
if ($(id).length > 0) { // not empty links
e.preventDefault(); // prevent normal link action

// this is the function call
console.log('click');
console.log('id = '+id); // IT PRINTS CORRECT HERE
console.log(typeof(id));
controller.scrollTo(id); // scroll on click

// update the URL
if (window.history && window.history.pushState) {
history.pushState("", document.title, id);
}
}
});


And here is the output of my console log:



click
id = #{the-href-value}
string
scroooooll
target = 0
number


My Javascript is pretty rusty, but this doesn't seem right to me. Why is it changing my variable from a string to a 0 when I pass it as a parameter?










share|improve this question























  • Have you tried debugging it in the browser?

    – Olian04
    Nov 16 '18 at 23:08











  • I am using my browser. The output is what the console log prints when I click the link. I'm trying to figure out where the 0 comes from.

    – Clara Olson
    Nov 16 '18 at 23:09













  • I'm talking about using the debugger, not just console.log. For example the chrome debugger.

    – Olian04
    Nov 16 '18 at 23:10






  • 1





    The first time you call controller.scrollTo you're passing it a function, the second time just an id. I don't know which one is right, but I imagine that's the reason for the discrepancy.

    – Jonny Rathbone
    Nov 16 '18 at 23:10











  • The way i understand it, it's supposed to be the scroll position of the target element. so it's supposed to be a number. 0 to me means you're giving it an id that doesn't match up with an element on the page, or the plugin is unable to get a y position for said element for whatever reason.

    – Kevin B
    Nov 16 '18 at 23:11
















0












0








0








I'm using scrollmagic.io and am making an anchor navigation menu. I'm following this tutorial. The scroll works! Except it was scrolling back to the beginning and not to the page it should be at.



Here is my code:



// init controller
var controller = new ScrollMagic.Controller();

// animate scroll instead of a jump
controller.scrollTo(function(target) {
console.log('scroooooll');
console.log('target = '+target); // THIS IS PRINTING 0
console.log(typeof(target));
/* Commenting out what it should do for simplicity. */
});

// scroll action when you click the nav links
$(document).on('click', 'a[href^=#]', function(e) {
var id = $(this).attr('href'); // get the href of clicked link
if ($(id).length > 0) { // not empty links
e.preventDefault(); // prevent normal link action

// this is the function call
console.log('click');
console.log('id = '+id); // IT PRINTS CORRECT HERE
console.log(typeof(id));
controller.scrollTo(id); // scroll on click

// update the URL
if (window.history && window.history.pushState) {
history.pushState("", document.title, id);
}
}
});


And here is the output of my console log:



click
id = #{the-href-value}
string
scroooooll
target = 0
number


My Javascript is pretty rusty, but this doesn't seem right to me. Why is it changing my variable from a string to a 0 when I pass it as a parameter?










share|improve this question














I'm using scrollmagic.io and am making an anchor navigation menu. I'm following this tutorial. The scroll works! Except it was scrolling back to the beginning and not to the page it should be at.



Here is my code:



// init controller
var controller = new ScrollMagic.Controller();

// animate scroll instead of a jump
controller.scrollTo(function(target) {
console.log('scroooooll');
console.log('target = '+target); // THIS IS PRINTING 0
console.log(typeof(target));
/* Commenting out what it should do for simplicity. */
});

// scroll action when you click the nav links
$(document).on('click', 'a[href^=#]', function(e) {
var id = $(this).attr('href'); // get the href of clicked link
if ($(id).length > 0) { // not empty links
e.preventDefault(); // prevent normal link action

// this is the function call
console.log('click');
console.log('id = '+id); // IT PRINTS CORRECT HERE
console.log(typeof(id));
controller.scrollTo(id); // scroll on click

// update the URL
if (window.history && window.history.pushState) {
history.pushState("", document.title, id);
}
}
});


And here is the output of my console log:



click
id = #{the-href-value}
string
scroooooll
target = 0
number


My Javascript is pretty rusty, but this doesn't seem right to me. Why is it changing my variable from a string to a 0 when I pass it as a parameter?







javascript scrollmagic






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 23:03









Clara OlsonClara Olson

185




185













  • Have you tried debugging it in the browser?

    – Olian04
    Nov 16 '18 at 23:08











  • I am using my browser. The output is what the console log prints when I click the link. I'm trying to figure out where the 0 comes from.

    – Clara Olson
    Nov 16 '18 at 23:09













  • I'm talking about using the debugger, not just console.log. For example the chrome debugger.

    – Olian04
    Nov 16 '18 at 23:10






  • 1





    The first time you call controller.scrollTo you're passing it a function, the second time just an id. I don't know which one is right, but I imagine that's the reason for the discrepancy.

    – Jonny Rathbone
    Nov 16 '18 at 23:10











  • The way i understand it, it's supposed to be the scroll position of the target element. so it's supposed to be a number. 0 to me means you're giving it an id that doesn't match up with an element on the page, or the plugin is unable to get a y position for said element for whatever reason.

    – Kevin B
    Nov 16 '18 at 23:11





















  • Have you tried debugging it in the browser?

    – Olian04
    Nov 16 '18 at 23:08











  • I am using my browser. The output is what the console log prints when I click the link. I'm trying to figure out where the 0 comes from.

    – Clara Olson
    Nov 16 '18 at 23:09













  • I'm talking about using the debugger, not just console.log. For example the chrome debugger.

    – Olian04
    Nov 16 '18 at 23:10






  • 1





    The first time you call controller.scrollTo you're passing it a function, the second time just an id. I don't know which one is right, but I imagine that's the reason for the discrepancy.

    – Jonny Rathbone
    Nov 16 '18 at 23:10











  • The way i understand it, it's supposed to be the scroll position of the target element. so it's supposed to be a number. 0 to me means you're giving it an id that doesn't match up with an element on the page, or the plugin is unable to get a y position for said element for whatever reason.

    – Kevin B
    Nov 16 '18 at 23:11



















Have you tried debugging it in the browser?

– Olian04
Nov 16 '18 at 23:08





Have you tried debugging it in the browser?

– Olian04
Nov 16 '18 at 23:08













I am using my browser. The output is what the console log prints when I click the link. I'm trying to figure out where the 0 comes from.

– Clara Olson
Nov 16 '18 at 23:09







I am using my browser. The output is what the console log prints when I click the link. I'm trying to figure out where the 0 comes from.

– Clara Olson
Nov 16 '18 at 23:09















I'm talking about using the debugger, not just console.log. For example the chrome debugger.

– Olian04
Nov 16 '18 at 23:10





I'm talking about using the debugger, not just console.log. For example the chrome debugger.

– Olian04
Nov 16 '18 at 23:10




1




1





The first time you call controller.scrollTo you're passing it a function, the second time just an id. I don't know which one is right, but I imagine that's the reason for the discrepancy.

– Jonny Rathbone
Nov 16 '18 at 23:10





The first time you call controller.scrollTo you're passing it a function, the second time just an id. I don't know which one is right, but I imagine that's the reason for the discrepancy.

– Jonny Rathbone
Nov 16 '18 at 23:10













The way i understand it, it's supposed to be the scroll position of the target element. so it's supposed to be a number. 0 to me means you're giving it an id that doesn't match up with an element on the page, or the plugin is unable to get a y position for said element for whatever reason.

– Kevin B
Nov 16 '18 at 23:11







The way i understand it, it's supposed to be the scroll position of the target element. so it's supposed to be a number. 0 to me means you're giving it an id that doesn't match up with an element on the page, or the plugin is unable to get a y position for said element for whatever reason.

– Kevin B
Nov 16 '18 at 23:11














1 Answer
1






active

oldest

votes


















1














From the documents:




"This function will be used for future scroll position modifications.
This provides a way for you to change the behaviour of scrolling and
adding new behaviour like animation. The function receives the new
scroll position as a parameter and a reference to the container
element using this. It may also optionally receive an optional
additional parameter (see below)"




So, the first parameter is passed by controller.
You will get your parameter after that.



http://scrollmagic.io/docs/ScrollMagic.Controller.html#scrollTo



Try printing console.log(args);



controller.scrollTo(function(scrollPos, targetHrefISent) {
console.log('scroooooll');
console.log('target = '+targetHrefISent); // THIS IS PRINTING 0
console.log(typeof(targetHrefISent));
/* Commenting out what it should do for simplicity. */
});





share|improve this answer
























  • This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

    – Clara Olson
    Nov 17 '18 at 23:04












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346517%2fjavascript-passing-my-string-as-an-argument-turns-it-to-a-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














From the documents:




"This function will be used for future scroll position modifications.
This provides a way for you to change the behaviour of scrolling and
adding new behaviour like animation. The function receives the new
scroll position as a parameter and a reference to the container
element using this. It may also optionally receive an optional
additional parameter (see below)"




So, the first parameter is passed by controller.
You will get your parameter after that.



http://scrollmagic.io/docs/ScrollMagic.Controller.html#scrollTo



Try printing console.log(args);



controller.scrollTo(function(scrollPos, targetHrefISent) {
console.log('scroooooll');
console.log('target = '+targetHrefISent); // THIS IS PRINTING 0
console.log(typeof(targetHrefISent));
/* Commenting out what it should do for simplicity. */
});





share|improve this answer
























  • This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

    – Clara Olson
    Nov 17 '18 at 23:04
















1














From the documents:




"This function will be used for future scroll position modifications.
This provides a way for you to change the behaviour of scrolling and
adding new behaviour like animation. The function receives the new
scroll position as a parameter and a reference to the container
element using this. It may also optionally receive an optional
additional parameter (see below)"




So, the first parameter is passed by controller.
You will get your parameter after that.



http://scrollmagic.io/docs/ScrollMagic.Controller.html#scrollTo



Try printing console.log(args);



controller.scrollTo(function(scrollPos, targetHrefISent) {
console.log('scroooooll');
console.log('target = '+targetHrefISent); // THIS IS PRINTING 0
console.log(typeof(targetHrefISent));
/* Commenting out what it should do for simplicity. */
});





share|improve this answer
























  • This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

    – Clara Olson
    Nov 17 '18 at 23:04














1












1








1







From the documents:




"This function will be used for future scroll position modifications.
This provides a way for you to change the behaviour of scrolling and
adding new behaviour like animation. The function receives the new
scroll position as a parameter and a reference to the container
element using this. It may also optionally receive an optional
additional parameter (see below)"




So, the first parameter is passed by controller.
You will get your parameter after that.



http://scrollmagic.io/docs/ScrollMagic.Controller.html#scrollTo



Try printing console.log(args);



controller.scrollTo(function(scrollPos, targetHrefISent) {
console.log('scroooooll');
console.log('target = '+targetHrefISent); // THIS IS PRINTING 0
console.log(typeof(targetHrefISent));
/* Commenting out what it should do for simplicity. */
});





share|improve this answer













From the documents:




"This function will be used for future scroll position modifications.
This provides a way for you to change the behaviour of scrolling and
adding new behaviour like animation. The function receives the new
scroll position as a parameter and a reference to the container
element using this. It may also optionally receive an optional
additional parameter (see below)"




So, the first parameter is passed by controller.
You will get your parameter after that.



http://scrollmagic.io/docs/ScrollMagic.Controller.html#scrollTo



Try printing console.log(args);



controller.scrollTo(function(scrollPos, targetHrefISent) {
console.log('scroooooll');
console.log('target = '+targetHrefISent); // THIS IS PRINTING 0
console.log(typeof(targetHrefISent));
/* Commenting out what it should do for simplicity. */
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 23:31









TeddyTeddy

2,43411838




2,43411838













  • This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

    – Clara Olson
    Nov 17 '18 at 23:04



















  • This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

    – Clara Olson
    Nov 17 '18 at 23:04

















This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

– Clara Olson
Nov 17 '18 at 23:04





This kinda helped. I passed an arbitrary number as my first parameter and it works now! Thanks

– Clara Olson
Nov 17 '18 at 23:04




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346517%2fjavascript-passing-my-string-as-an-argument-turns-it-to-a-0%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Bressuire

Vorschmack

Quarantine