First question on SO...please forgive me if it's poorly done.
This appears to be a normally discussed problem (a search yields dozens if not hundreds of posts "my JS only works on page refresh" all solved by using
jquery-turbolinks and adding it to
I've taken all those steps. However I'm experiencing something that almost no one else references...
Here's what we've got:
This adds the
localScroll animation to the div I'm using:
The JS libraries I'm using (links broken since I'm a newb and can only include up to two links in a post...):
- github. com/flesler/jquery.scrollTo
- github. com/flesler/jquery.localScroll
Both are downloaded and added to
Both are required in
application.js (the last two before
//= require_tree .).
I've installed and added
jquery-turbolinks to my
gemfile, run Bundler, required it in
turbolinks but after
jquery), and stopped/started the rails server.
I didn't add all the details around the div and name/href combinations I'm using since the animation does does work once. I'm assuming my problem is very closely related to what everyone else experiences, but I just can't find a solution.
Any help would be highly appreciated.
//= require jquery //= require jquery.turbolinks //= require jquery_ujs //= require turbolinks //= require_tree .
require_tree . does grab them (I inspected the page after it loaded to verify).
This pops the alert every time any page in the application is loaded after the page with the function has been called.
Then it pops the alert twice on any new page if I load the page with the function again. Then three times if I load it again...I'm assuming that something under the hood is interfering with with this JS which is why the
.localScroll call itself isn't working...
UPDATE 2 Alternate solution
I ended up abandoning trying to work with localScroll and scrollTo and instead just used this agnostic internal link interceptor: