演示:https://codepen.io/livehelp/pen/MWoNPqX?editors=1010
只需在Elementor中使用HTML或Code元素来粘贴代码,而不是使用Button元素。
<h2><a href="#smooth" onclick="window.open(\'https://downloads.wordpress.org/plugin/apk-downloader.zip\')";>Click to Download + Smooth Scroll</a></h2>
<p>Insert enough text here to have a scoll bar.</p>
<div id="smooth"><h1>Tadaa! Jumps to this div based on the id #smooth onClick.<h1></div>
<script>
const links = document.querySelectorAll("a");
for (const link of links) {
link.addEventListener("click", clickHandler);
}
function clickHandler(e) {
e.preventDefault();
const href = this.getAttribute("href");
const offsetTop = document.querySelector(href).offsetTop;
scroll({
top: offsetTop,
behavior: "smooth"
});
}
</script>