h5移動端禁止長按圖片保存


在移動端訪問H5頁面的時候,長按圖片就會把圖片保存起來,為了能夠讓用戶體驗更好一些,我們需要長按的時候也不保存圖片。那該如何實現呢?下面給出3種解決方案。

 

方案一:使用 pointer-events:none

img{
   pointer-events:none;
}

  

親測有效,適用於微信客戶端的手機頁面,圖片被打開的情況.

 

方案二:全局屬性

*{
   -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

  

-webkit-touch-callout主要用於禁止長按菜單。當然針對webkit內核的瀏覽器。

user-select屬性是css3新增的屬性,用於設置用戶是否能夠選中文本。

攝圖網https://www.wode007.com/sites/73204.html VJ師網https://www.wode007.com/sites/73287.html

方案三:加一層遮罩層  

圖片上邊加一層div類似於遮罩層,這樣圖片就不會被點擊,右擊或長按也不會出現如圖的圖片另存為的選項了。  代碼示例如下:

<div class="imgbox">
    <div class="imshar"></div>
    <img src=""/>
</div>
<style>
 .imgbox{
    position: relative;
    width: 80%;
    margin: 0 auto;
    margin-top: 20px;
}
 .imgbox .imshar{
    position: absolute;
    z-index: 100;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    opacity: 0;
}
.imgbox img{
    display: block;
    width: 100%;
}
</style>

  

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM