jquery - Rails: Bootstrap Collapse doesn't work after refresh -
i have simple bootstrap collapse (as seen working in this fiddle):
<h3> <a data-toggle="collapse" href="#collapseexample" aria-expanded="false" aria-controls="collapseexample"> our name</a> </h3> <div class="collapse" id="collapseexample"> <p> stuff our name. <p> </div> <h3> <a data-toggle="collapse" href="#collapsetwo" aria-expanded="false" aria-controls="collapsetwo"> bottom line basics</a> </h3> <div class="collapse" id="collapsetwo"> <p> more words! </p> </div> i trying put in "about us" page. works fine in jsfiddle, in rails app, see behavior:
load different page (not us), navigate "about us" page: collapse works fine.
refresh "about us" page: collapse doesn't work.
i figure has turbolinks, nothing i'm trying working.
it ended being interference on click event caused this "smooth scrolling" script.
i fixed matching against "collapse":
$('a[href*=#]:not([href*=#collapse])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrolltop: target.offset().top }, 1000); return false; } } });
Comments
Post a Comment