移动端H5页面阻止图片和文字被选中

H5页面设置图片和span标签等不可选中
1.阻止span标签等文字被选中
在对应元素的CSS样式中加
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
2.阻止浏览器点击图片查看的行为(常见于uc浏览器)
1.背景图的方式插入(这种是比较普遍的方式)
background:url(./img/tip.png) norepeat center;
background-size: cover;
2.使用js事件阻止默认行为的方法
const imgMask = document.getElementById(‘mask’);
imgMask.addEventListener(‘click’, function (event) {
event.stopPropagation();
event.preventDefault();
});

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理