js擷取滑鼠座標執行個體

來源:互聯網
上載者:User

標籤:style   color   os   java   io   ar   div   cti   代碼   

js擷取滑鼠座標執行個體,關鍵代碼如下:

1.js 代碼

/*顯示座標*/function showTip(obj){//if(!$.trim($(obj).html()))//return false;var event=window.event;var element=event.srcElement;//var X = $(obj).position().top;//var Y = $(obj).position().left;//alert(X+","+Y);var X = $(obj).offset().top;var Y = $(obj).offset().left;var e = event || window.event;var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;var scrollY = document.documentElement.scrollTop || document.body.scrollTop;var px = e.pageX || e.clientX + scrollX;var py = e.pageY || e.clientY + scrollY;$(‘#tipDiv‘).css("top",X+15+scrollY);$(‘#tipDiv‘).css("left",Y+10+scrollX);$(‘#tipDiv‘).css("width",$(obj).width()+10);//X:710 850 Y:430 560//var xValue=parseInt(px);//var yValue=parseInt(py);        $(‘#tipDiv‘).html("x:"+px+" y:"+py);        $(‘#tipDiv‘).show();}/*隱藏座標*/function hideTip(obj){$(‘#tipDiv‘).hide();}

 2.body關鍵代碼

<img class="center-block" src="../../images/map/12345.png" alt="地圖" style="height: 640px;" onmousemove="showTip(this)" onmouseout="hideTip(this)" onclick="showCityInfo()">

3.div代碼(用於顯示座標)

<div id="tipDiv" style="position: absolute;display:none;text-align:left; border: 1px solid green;z-index: 10000;width:100px;color: red;background-color: #FFF"></div>


js擷取滑鼠座標執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.