jquery 簡短几句代碼實現給元素動態添加及擷取提示資訊

來源:互聯網
上載者:User

還是要首先引用JQ架構。

然後來看看效果:(串連添加不上)只能暫時看哈圖片, 具體效果可參見我部落格左方“My Box”中的“玩遊戲”:

下面代碼中有具體注釋。

再來看看代碼:
複製代碼 代碼如下:
<div id="_gameinfo" style="width:158px; border:1px #FFC solid; background-color:#FFF; position:fixed; z-index:101; display:none;padding:1px;">
</div>
<div id="thegameBox" style="text-align:center;">
<a href="javascript:;" alt="WASD鍵控制小女孩移動,方向鍵控制小男孩的移動,不同顏色的陷阱只能容納不同顏色的人通過哦!" name="binghuoren">深林冰火人</a>
<a href="javascript:;" alt="滑鼠點擊抓東西。" name="zhishangqiu">智商球3</a>
<a href="javascript:;" alt="滑鼠操作,移動滑鼠控制機械手移動,點擊左鍵釋放磁吸力抓住貨物。" name="yunshuchuan">船長的運輸船</a>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#thegameBox a").mousemove(function(ev){
var _Imgsrc="http://www.bkjia.com/uploads/allimg/131016/23422L525-1.jpg";//這裡需要將元素name設定和你的圖片名字一樣
var _Ways=$(this).attr("alt");//擷取當前滑鼠指著的元素的alt
$("#_gameinfo").show();//顯示提示層
if(!ev){ev=window.event;};//檢測是否為IE
document.getElementById("_gameinfo").style.left=(ev.clientX+10)+"px";//設定提示資訊left為滑鼠的X軸距離+10px
document.getElementById("_gameinfo").style.top=(ev.clientY+10)+"px";//設定提示資訊top為滑鼠的X軸距離+10px
$("#_gameinfo").html('<img src="'+_Imgsrc+'" alt="" width="158" height="117" style="margin-bottom:3px;" /><br />'+'<font color="blue">操作方法:</font>'+_Ways+'');//給提示層裡面新增內容並傳入參數
}).mouseout(function(){
$("#_gameinfo").hide();//滑鼠離開元素提示層隱藏
})
})
</script>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.