css - Bootstrap affix navbar only works on refresh -
i'm trying create website friend of mine (for learning purposes also). , i'm trying create affix navbar bootstrap. (btw i'm coding on cloud9 using ruby on rails).
if preview site, affix navbar works fine, after clicking on link in navbar, navbar stays on position below banner. through inspecting element, found out affix classes don't appended navbar anymore, after clicking 1 of links. i've spent hours trying , fixing nothing seems work.
so hope 1 of guys can me out. in advance.
the code application.html.erb is:
<!doctype html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>nl-renovatie</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body data-spy="scroll" data-target="nav" data-offset="50"> <div class="container-fluid header"> <h1>bootstrap affix example</h1> <h3>fixed (sticky) navbar on scroll</h3> <p>scroll page see how navbar behaves data-spy="affix".</p> </div> <nav class="navbar navbar-inverse navbar-static-top" role="navigation" data-spy="affix" data-offset-top="197"> <div class='container-fluid'> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-nav-collapse"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <%= link_to root_path, class: 'navbar-brand' %> <i class="fa fa-home fa-lg"aria-hidden="true"></i> home <% end %> </div> <div class="collapse navbar-collapse" id="main-nav-collapse"> <ul class="nav navbar-nav navbar-left"> <li id='navbar-button'> <%= link_to overons_path %> <i class="fa fa-users" aria-hidden="true"></i> on ons <% end %> </li> <li id='navbar-button'> <%= link_to new_contact_path %> <i class="fa fa-envelope" aria-hidden="true"></i> contact <% end %> </li> </ul> </div><!-- /.navbar-collapse --> </div> </nav> <div class="container-fluid"> <% flash.each |key, value| %> <%= content_tag :div, value, class: "alert alert-#{key}" %> <% end %> <%= yield %> </div> </body> </html>
the code application.css.scss :
@import "bootstrap-sprockets"; @import "bootstrap"; @import "font-awesome-sprockets"; @import "font-awesome"; .affix { top: 0; width: 100%; } .affix + .container-fluid { padding-top: 70px; } .header { background-color:#f44336; color:#fff; height:200px; }
the problem caused turbolinks. fix following:
in application.js file had remove following line:
//= require turbolinks
and in application.html.erb i've set both data-turbolinks-track false:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => false %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => false %>
Comments
Post a Comment