Lastor
[Coding] 真是個有趣的坑,遇到一個技術需求,需要把 web 頁面 scroll to top,但不要 smooth,要瞬間上去
Lastor
用現在瀏覽器的香草 api,window.scrollTo() 處理,但偏偏怎麼設定都會 smooth
Lastor
查半天原來是 Bootstrap 有控制 scroll 的作用方式.....
https://imgs.plurk.com/QzN/pkJ/aGzNdX6XcaveATage4qabfsG4HM_lg.png
Lastor
而且是寫在 :root 也就是 html tag 上面
Lastor
平常從沒對 html tag 下過 CSS,原來那可以控制啊.....
Lastor
DOM 的呼叫方式也比較不一樣,是 document.documentElement
Lastor
=============
笑了,話說這主要是為了解決 html2canvas 套件,拍圖會偏移的問題,研究其規律,在 scrollbar 是 0, 0 的時候就不會偏移
Lastor
所以才想到這個奧步,乾脆 code 手動歸零再拍
Lastor
然後才看到,果然大家都有想到這招
HTML2Canvas does not render full div, only what is v...
Lastor
目前看來,與其說是這套件的 bug,不如說這套件的數學計算寫的比較活版,只是他文件沒寫得那麼細
Lastor
他會根據整個 screen 的 size,scroll 的 position 都去做計算,並且可以設定他
Lastor
對這個算法原裡比較有概念的,可以透過設定解決
Lastor
但正常人應該沒事都不會研究過這種東西...... 最暴力無腦的就是直接手動 scrollTo 歸零再拍圖
載入新的回覆