我正在构建我的第一个 Ruby on Rails 应用程序,并尝试创建一个动画导航栏。我正在使用 jQuery 和 Turbolink。
这是我的application.js
(under /app/assets/javascripts
)
$(document).ready(function(){
$("#nav").hover(function(){
$("#nav").animate({left:'10px'});
},
function(){
$("#nav").animate({left:'-220px'});
});
});
And on application.html.erb
(under app/views/layouts
), 我有
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
和我的超级导航栏,现在看起来像这样(也在应用程序/视图/布局下)
<div id='nav'>
<%= image_tag('arrow.png', size: '20x20', id: "arrow") %>
<ul>
<li><%= link_to 'Main page', root_path%></li>
<li><%= link_to 'Résumé', resume_path %></li>
</ul>
</div>
When I load my app, the animation works, but when I navigate to an other page of the app, the animation stops working. If I press F5, it's working again
因此,如果我想使用导航栏,我必须刷新每个页面。
你知道我能做什么来解决这个问题吗?