页面a标签锚点

滚动到指定位置

html

<div id="锚点id"></div>

js

const insertLink = (val) => {
    
    
    var a = document.createElement("a");
    let href = val;
    a.setAttribute("href", href);
    a.setAttribute("target", "_blank");
    a.setAttribute("id", "startTelMedicine");
    a.onclick = function () {
    
    
        //关闭窗口的方法
        window.opener = null;
        window.open("", "_self", "");
        window.close();
    };
    // 防止反复添加
    if (document.getElementById("startTelMedicine")) {
    
    
        document.body.removeChild(document.getElementById("startTelMedicine"));
    }
    document.body.appendChild(a);
    a.click();
};

css

html,body{
    
    
	scroll-behavior:smooth;//页面滚动时动画
}

猜你喜欢

转载自blog.csdn.net/weixin_49295874/article/details/129212979