{"id":6127,"date":"2014-04-13T04:33:05","date_gmt":"2014-04-13T04:33:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/jquery-scrolling-animation-works-but-window-location-hash-screws-it-over-collection-of-common-programming-errors-2\/"},"modified":"2014-04-13T04:33:05","modified_gmt":"2014-04-13T04:33:05","slug":"jquery-scrolling-animation-works-but-window-location-hash-screws-it-over-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/jquery-scrolling-animation-works-but-window-location-hash-screws-it-over-collection-of-common-programming-errors-2\/","title":{"rendered":"jQuery scrolling animation works, but window.location.hash screws it over-Collection of common programming errors"},"content":{"rendered":"<p>Trying to solve this issue for 2 days now without success.<\/p>\n<p>I have a main nav bar located in a single page website. The website has a scrolling animation. Whenever the user clicks a link from the nav bar, the window.location.hash should change.<\/p>\n<p>Now, the thing is that it USED to change. But at the same time, it had flickering issues (which I couldn&#8217;t resolve with e.preventDefault()). The only way to stop the flickering was to add the stop() to the window.location.hash. So now I don&#8217;t have the flickering but the window.location.hash doesn&#8217;t change anymore, which isn&#8217;t a good thing.<\/p>\n<p>This is the code<\/p>\n<pre><code>\n   \n    <\/code><\/pre>\n<ul class=\"floatRight\">\n<li><code>Home<\/code><\/li>\n<li><code>About<\/code><\/li>\n<li><code>Platform<\/code><\/li>\n<li><code>Investors<\/code><\/li>\n<li><code>Team<\/code><\/li>\n<li><code>News &amp; Press<\/code><\/li>\n<li class=\"last\"><code>Startup Explained<\/code><\/li>\n<\/ul>\n<pre>\n    \n\n    \n\nfunction gotoAndScroll(to){\n    if(typeof to == 'string') {\n        var diff = (to == '#newsPress')? 74 : 83;\n        $.scrollTo( {top: $(to).offset().top - diff}, 1500, {axis:'y',easing:'easeInOutCubic'});\n    }\n    else if(typeof to == 'number'){\n        $.scrollTo({top:Number(to), left:0},{duration:1500});\n    }\n}\n\n$('.nav a').click(function(e) {\n\n    if($(this).data('to') != '#home')\n        gotoAndScroll($(this).data('to'));\n    else \n        gotoAndScroll(0);\n        window.location.hash = $(this).data('to').stop();\n});    \n\n$('a#logo').click(function(e) {\n    if($(this).data('to') != '#home')\n        gotoAndScroll($(this).data('to'));\n    else \n        gotoAndScroll(0);\n        window.location.hash = $(this).data('to').stop();\n});    \n\n    \n\n\n\n<\/pre>\n<p><code>Edit:<\/code><\/p>\n<p><code>When clicking one of the nav links, I get the next error: Uncaught TypeError: Object #about has no method 'stop' Uncaught SyntaxError: Illegal return statement<\/code><\/p>\n<p><code>I realize that stop() shouldn't be there, but, against all logic, that's the only thing that fixes the flickering.<\/code><\/p>\n<p><code>Can anyone tell me what I'm doing wrong here? :\/ Thanks in advance.<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trying to solve this issue for 2 days now without success. I have a main nav bar located in a single page website. The website has a scrolling animation. Whenever the user clicks a link from the nav bar, the window.location.hash should change. Now, the thing is that it USED to change. But at the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6127","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6127"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6127\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}