我在使用 codepen 上的滑塊時遇到問題。我已經在我的網站上實作了它,并認識到如果我在網站上滾動,內容的白色突出顯示正在移動。白色熒光筆上下移動。我真的不知道如何解決這個問題。原始代碼也有同樣的問題。也許有人有想法?代碼位于 codepen.io/JavaScriptJunkie/pen/ZMMRRQ
uj5u.com熱心網友回復:
讓我知道這是否符合您的預期 :) 這只是我更改的 javascript: lhttps ://pastebin.com/MPB4fQQml
主要重點是您正在嘗試獲取 y 軸的 getBoundingClientRect()。但是,y 軸始終保持不變。
uj5u.com熱心網友回復:
getBoundingClientRect() 為螢屏上當前視圖中的矩形提供坐標。通過簡單地將 window.pageYOffset(即視口上方到頁面頂部的高度)添加到新的 Y 坐標,您可以偏移這個移動的 Y 位置。
請參閱 Codepen 的這個分支中的 16:https ://codepen.io/yoat/pen/XWzqRKJ
var x = this.getBoundingClientRect().left;
// only the y position changes, not the X or the height!
var y = this.getBoundingClientRect().top window.pageYOffset;
var width = this.getBoundingClientRect().width;
var height = this.getBoundingClientRect().height;
uj5u.com熱心網友回復:
是否可以“預先突出顯示”內容?只有當我將滑鼠放在那里時,它才會突出顯示......
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/430343.html
標籤:javascript html css json getboundingclientrect
上一篇:如何在JetpackCompose的水平尋呼機中添加影片?
下一篇:CORS策略已阻止從源“http://localhost:63342”訪問“http://localhost:8000/api/auth/jwt/create/”處的XMLHttpRequest:
