• 浏览器获取鼠标光标坐标


    function getSelectionCoords(win) { 
      win = win || window;
      var doc = win.document; 
      var sel = doc.selection, range, rects, rect; 
      var x = 0, y = 0; 
      if (sel) { 
        if (sel.type != "Control") { 
          range = sel.createRange(); 
          range.collapse(true); 
          x = range.boundingLeft; 
          y = range.boundingTop; 
        } 
      } else if (win.getSelection) { 
        sel = win.getSelection(); 
        if (sel.rangeCount) { 
          range = sel.getRangeAt(0).cloneRange(); 
          if (range.getClientRects) { 
            range.collapse(true); 
            rects = range.getClientRects(); 
            if (rects.length > 0) {
              rect = rects[0]; 
            } 
            if(rect){ 
              x = rect.left; 
              y = rect.top; 
            } 
          }
          if ((x == 0 && y == 0) || rect === undefined) { 
            var span = doc.createElement("span"); 
            if (span.getClientRects) {
              span.appendChild(doc.createTextNode("u200b")); 
              range.insertNode(span); 
              rect = span.getClientRects()[0]; 
              x = rect.left; 
              y = rect.top; 
              var spanParent = span.parentNode; 
              spanParent.removeChild(span);
              spanParent.normalize(); 
            } 
          } 
        } 
      } 
      return { x: x, y: y }; 
    }
  • 相关阅读:
    linux报错pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
    解决Pandas读取文件丢失数据前的0问题
    TensorFlow 2.8 kerastensor和tensor在输入时会有冲突
    TensorFlow 的Keras 和本地keras的区别
    Android Termux 安装 Linux
    如何关闭Mac电脑的Microsoft AutoUpdate弹框
    python中文件路径的格式
    ubuntu18.04 彻底卸载 docker
    windows 7 证书无效
    vuex入门使用详解
  • 原文地址:https://www.cnblogs.com/litings/p/13862396.html
Copyright © 2020-2023  润新知