3 回答

TA貢獻1851條經驗 獲得超5個贊
更改該參數并沒有改變我的東西。我遵循了QuantumPuter關于scrollIntoView的建議并且它起作用了(最終不需要JQuery。我添加了術語“href =“#openmenu”onclick =“window.location.hash ='#menu1'””來證明我們可以結合其他東西放在一起并使滾動仍然有效)。
https://jsfiddle.net/7k1s6t80/
<div style="height:3000px">
<a id="forscroll" href="#openmenu" onclick="window.location.hash = '#menu1'">Down</a>
<a id="here" style="position:absolute; top: 2000px;"></a>
</div>
<script>
const target = document.getElementById('here'),
button = document.getElementById('forscroll');
button.addEventListener('click',
function(){target.scrollIntoView({block: 'start',behavior:'instant',inline:'start'});});
</script>
另外,為了回答我的問題,使 JQuery 滾動即時(就像我想的那樣與隊列有關)=>
$('html,body').animate({scrollTop: e.offset().top},{queue: false,duration: 0})

TA貢獻1851條經驗 獲得超4個贊
將 '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>
添加回答
舉報