我window.scrollBy()用于平滑滚动,但它不适用于 Safari。修复它的最佳方法是什么?
function scroll(id: number) {
for (let k = 0; k < sectionsForScroll.length; k++) {
if (sectionsForScroll[k].dataset.navId == id) {
const bigginer = sectionsForScroll[0].getBoundingClientRect().top;
console.log(bigginer + 'px how far we from the start ');
const distanceToGo = sectionsForScroll[k].getBoundingClientRect().top;
console.log(sectionsForScroll[k].offsetTop);
const distanceToScroll = bigginer - distanceToGo;
console.log(distanceToGo + ' where we have to go ');
console.log(distanceToScroll + ' what the distanse we need to scroll ');
window.scrollBy({left:0, top:distanceToGo, behavior:"smooth"});
}
}
}
Run Code Online (Sandbox Code Playgroud) 我必须抓住"悬停"并调用JS函数.我从html中调用它.但什么都没发生.我也尝试使用鼠标悬停 - 也无法使用html.我必须抓住"悬停",但不能在"hover"上的JS文件中创建事件监听器.我可以将事件监听器置于"鼠标悬停"但是当鼠标快速移动时它不能正常工作).我犯了什么错误,我对changeDef(事件)没有任何反应?
function changeDef(event){
console.log(event.target);
}Run Code Online (Sandbox Code Playgroud)
<img class="img-default" src="./img/footer1.png" hover="changeDef(event)">Run Code Online (Sandbox Code Playgroud)