拖動效果,防止選中文字兼容代碼


css 設置方法:
-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit瀏覽器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期瀏覽器*/
 user-select: none;

 

js 設置方法:

window.getSelection? window.getSelection().removeAllRanges():document.selection.empty();

 對比不同:

css 的設置方法是禁止用戶選中文字,無論是否是在拖拽效果下;

js 的設置方法是為了保證在拖拽時,禁止文字選中;

代碼示例如下:

 document.onmousemove = function () {
    window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
 }

這樣設置后,當鼠標在拖拽的時候就不會選中文字了


免責聲明!

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



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