亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JQuery 滾動速度請為瞬時

JQuery 滾動速度請為瞬時

海綿寶寶撒 2023-10-14 18:12:18
我希望我的 JQuery 滾動速度是瞬時的(不平滑/不快,但像經典的錨 href="#" 一樣瞬時)。這似乎與隊列有關,但我該如何更改我的腳本?感謝您的幫助。https://jsfiddle.net/7f1Ldeqr/<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>
查看完整描述

3 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

不使用快速,而是將其替換為僅使用 0 的 0.2 之類的值似乎不起作用,因此接近 0 的超小值就可以解決問題。



查看完整回答
反對 回復 2023-10-14
?
江戶川亂折騰

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})


查看完整回答
反對 回復 2023-10-14
?
繁花不似錦

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>


查看完整回答
反對 回復 2023-10-14
  • 3 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號