当我向下滚动页面时,Scrollspy导致我的li在第一个和第二个li之间闪烁,但是一旦我到达最后一个部分,正确的li变为活动状态。我很确定这必须对AJAX做些什么,但无法弄清楚原因。当我刷新页面时,scrollspy完美地运行。任何想法为什么会这样?我尝试过一切都没有成功。
身体标签
<body data-spy="scroll" data-target=".stickysteps">
如何调用scrollspy
<% if manual.present? && manual.steps.present? %>
<div class="stickysteps">
<ul class="nav nav-pills">
<% n = 0 %>
<% @manual.steps.order(:priority).each do |step| %>
<li><a href="#step<%= n+1 %>"><h4>Step <%= n + 1 %></h4></a></li>
<% n += 1 %>
<% end %>
</ul>
</div>
<h1 style="margin-left: 20px;">Your Instructions:</h1> </br>
<% steps = manual.steps.order(:priority) %>
<%= render(steps.order(:priority), steps: steps) %>
<% end %>
<script type="text/javascript">
$('.stickysteps').scrollspy();
$('[data-spy="scroll"]').each(function () {
$('.stickysteps').scrollspy('refresh');
});
offsetValue = 168;
$('body').data().scrollspy.options.offset = offsetValue;
// force scrollspy to recalculate the offsets to your targets
$('body').data().scrollspy.process();
</script>
<%= javascript_include_tag "manuals" %>
<%= javascript_include_tag "imagezoom" %>