[英]Scrolling to a Specific Anchor After JS Animation/Sequence
I have a simple function that loads after some questioned are clicked and it works fine, but I would like to scroll the page to the anchor with the .step_button
class at the end of the questions: 我有一个简单的函数,可以在单击某些问题后加载,并且可以正常工作,但是我想在问题的末尾使用.step_button
类将页面滚动到锚点:
<div id="if_one">
<a class="step_button" href="http://link2.com">IF QUESTION 1 = Option 1</a>
</div>
<div id="if_two">
<a class="step_button" href="http://link1.com">IF QUESTION 1 = Option 2</a>
</div>
<div id="if_three">
<a class="step_button" href="http://link1.com">IF QUESTION 1 = Option 3</a>
</div>
I think the part of the javascript that would have to be changed is: 我认为必须更改的javascript部分是:
function run_loading_4(q1) {
$('.run_loading_4, .loading').hide();
$('.li_run_loading_4, li_run_loading_5, .run_loading_5, .show_end').fadeIn();
$('#' + q1).show();
}
But I'm not sure.. I also found a way to include a JSFIDDLE so should be easier to figure out, I added a bunch of <br />
to the fiddle to make sure that the working solution will scroll to the anchors for step_button
但是我不确定。.我还找到了一种包含JSFIDDLE的方法,因此应该更容易弄清楚,我在小提琴中添加了一堆<br />
以确保工作解决方案可以滚动到锚点step_button
Change the function to something like this: 将函数更改为如下所示:
function run_loading_4(q1) {
$('.run_loading_4, .loading').hide();
$('.li_run_loading_4, li_run_loading_5, .run_loading_5, .show_end').fadeIn();
$('#' + q1).show();
$('html,body').animate({
scrollTop: $("#"+q1).offset().top},
'slow');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.