Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery scrollspy活动类在AJAX中闪烁_Jquery_Html_Ajax_Twitter Bootstrap - Fatal编程技术网

Jquery scrollspy活动类在AJAX中闪烁

Jquery scrollspy活动类在AJAX中闪烁,jquery,html,ajax,twitter-bootstrap,Jquery,Html,Ajax,Twitter Bootstrap,当我向下滚动页面时,Scrollspy导致我的li在第一个和第二个li之间闪烁,但一旦我到达最后一个部分,正确的li就会激活。我很确定这与AJAX有关,但不知道为什么。当我刷新页面时,scrollspy工作得非常好。知道为什么会这样吗?我什么都试过了,但没有成功 身体标签 <body data-spy="scroll" data-target=".stickysteps"> 如何称呼scrollspy <% if manual.present? && ma

当我向下滚动页面时,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" %>

你的指示:
$('.stickysteps').scrollspy(); $('[data spy=“scroll”]')。每个(函数(){ $('.stickysteps').scrollspy('refresh'); }); offsetValue=168; $('body').data().scrollspy.options.offset=offsetValue; //强制scrollspy重新计算到目标的偏移量 $('body').data().scrollspy.process();
您是否尝试过将jQuery函数包装到document.ready语句中?当脚本运行时,页面可能并没有完全加载,所以会产生闪烁的效果。javascript第二行中的每一个页面的用途是什么?它在所有stickysteps元素上运行了n次刷新方法,这可能不是故意的。是的,可能是。Boostrips文档就是这么说的。“当将scrollspy与从DOM中添加或删除元素一起使用时,您需要像这样调用刷新方法:$('[data spy=“scroll”]')。每个(函数(){var$spy=$(this).scrollspy('refresh'));”添加该函数后,整个过程中只突出显示最后一步