Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.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
Javascript JQuery的滚动速度是瞬时的,请_Javascript_Html_Jquery_Smooth Scrolling_Instant - Fatal编程技术网

Javascript JQuery的滚动速度是瞬时的,请

Javascript JQuery的滚动速度是瞬时的,请,javascript,html,jquery,smooth-scrolling,instant,Javascript,Html,Jquery,Smooth Scrolling,Instant,我希望我的JQuery滚动速度是瞬时的(不平滑/不快,但像经典的锚href=“#”)一样是瞬时的。这似乎是关于队列的问题,但我如何才能更改脚本?谢谢你的帮助 <div style="height:3000px"> <a href="#" id="link">Down</a> <a name="here" style="position:relative; top:

我希望我的JQuery滚动速度是瞬时的(不平滑/不快,但像经典的锚href=“#”)一样是瞬时的。这似乎是关于队列的问题,但我如何才能更改脚本?谢谢你的帮助

<div style="height:3000px">
<a href="#" id="link">Down</a>
<a name="here" style="position:relative; top:2000px;"></a>
</div>

<script src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.js'></script>
<script>
function scrolling(aid){
var aTag = $("a[name='"+ aid +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'fast');}
$("#link").click(function() {
scrolling('here');});
</script>

功能滚动(辅助){
var aTag=$(“a[name='”+aid+']);
$('html,body').animate({scrollTop:aTag.offset().top},'fast');}
$(“#链接”)。单击(函数(){
滚动('here');});

将“fast”替换为0。第二个参数是以毫秒为单位的持续时间

<script>
function scrolling(aid){
var aTag = $("a[name='"+ aid +"']");
$('html,body').animate({scrollTop: aTag.offset().top},0);}
$("#link").click(function() {
scrolling('here');});
</script>

功能滚动(辅助){
var aTag=$(“a[name='”+aid+']);
$('html,body').animate({scrollTop:aTag.offset().top},0);}
$(“#链接”)。单击(函数(){
滚动('here');});

不要使用fast,而是用0.2之类的东西替换它,仅使用0似乎不起作用,因此接近0的超小值就可以了。

谢谢您的回答。改变那个参数对我来说并没有改变任何东西。我遵循了quantumPuter关于scrollIntoView的建议,它起到了作用(最终不需要JQuery。我添加了“href=“#openmenu”onclick=“window.location.hash=”#menu1“”,以证明我们可以将其他内容组合在一起,并使滚动仍然有效)

<div style="height:3000px">
<a href="#" id="link">Down</a>
<a name="here" style="position:relative; top:2000px;"></a>
</div>

<script src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.js'></script>
<script>
function scrolling(aid){
var aTag = $("a[name='"+ aid +"']");
$('html,body').animate({scrollTop: aTag.offset().top},'fast');}
$("#link").click(function() {
scrolling('here');});
</script>

这只是在黑暗中拍摄,但请尝试将instant作为参数值的scrollIntoViewOptions。我是从这里得到这个主意的。也许jQuery一个人做不到。谢谢你的帮助。它起作用了!我要发布脚本。哦,我明白了,谢谢你用你的答案为平台做贡献:)
$('html,body').animate({scrollTop: e.offset().top},{queue: false,duration: 0})