jquery 鼠標停留顯示提示框,提示框位置跟隨鼠標移動

這段代碼經過演示,可以達到標題所說的效果,注意需要引入js文件

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery鼠標經過淡入顯示提示框 演示</title>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<style type="text/css">
.div{ border:1px solid #0000FF; float:left; width:200px; height:200px; margin:10px;}
div#tip{ position:absolute; width:100px; height:auto; border:1px solid #00CC66;}
.div1{border:0;cursor:pointer;width:auto; height:auto;}
</style>
</head>

<body>

<div id="tip" style="display:none">提示內容</div>
<div class="div"></div>
<div class="div"></div>
<div class="div div1">enenba</div>
<script type="text/javascript">
 $(document).ready(function(){
  $('.div').hover(
   function(){
    $('#tip').fadeIn('slow');
   }
  );
  
  $('.div').mousemove(function(e){
   var top = e.pageY+5;
   var left = e.pageX+5;
   $('#tip').css({
    'top' : top + 'px',
    'left': left+ 'px'
   });
  });
  
  $('.div').mouseout(function(){
   $('#tip').hide();
  });
  
 });
</script>
</body>
</html>

發佈了4 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章