Blogger Information
Blog 37
fans 0
comment 1
visits 28435
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js 自定义data-herf属性链接跳转
kong
Original
3025 people have browsed it

在移动端网页我们使用a标签跳转此时点击之后浏览器会等待200~300ms时间看看你有没有第二次点击,如果200~300ms以内没有点击,此时触发你的click事件,如果有点击,则你的click事件业务不发生,而是放大视口。但是touchstart不会等待,只要你碰到了屏幕一定会执行touchstart事件;

代码如下

//先获取data-herf的属性

var hrefs = document.querySelectorAll("[data-href]");

//循环语句给所有data-herf属性的元素添加超级链接

for(var i = 0; i < hrefs.length; i++){
    //绑定touchstart事件
    hrefs[i].addEventListener("touchstart",function(){
    //核心语句
	window.location = this.getAttribute("data-href");
    },true);
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post