JavaScript通過mouseover()實現(xiàn)圖片變大效果的示例
更新時間:2017年12月20日 08:30:53 作者:AJin0802
下面小編就為大家分享一篇JavaScript通過mouseover()實現(xiàn)圖片變大效果的示例,具有很好的參考價值,希望對大家有所幫助
實例如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>圖片提示</title>
<!--jQuery -->
<script src="../jquery.min.js"type="text/javascript"></script>
<style type="text/css">
body{
margin:0;
padding:40px;
background:#fff;
font:80% Arial, Helvetica, sans-serif;
color:#555;
line-height:180%;
}
img{border:none;}
ul,li{
margin:0;
padding:0;
}
li{
list-style:none;
float:left;
display:inline;
margin-right:10px;
border:1px solid #AAAAAA;
}
/* tooltip */
#tooltip{
position:absolute;
border:1px solid #ccc;
background:#333;
padding:2px;
display:none;
color:#fff;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
var x=1,y=1;
var myHref;
$("a[class=tooltip]").mouseover(function(e){//鼠標懸停的時候
myHref=this.href;//獲取大圖片
var $div=$("<div id='tooltip'><img src='"+myHref+"'></img></div>");//創(chuàng)建一個div
$("body").append($div);//把div添加到body中
$("#tooltip").css({
top:e.pageY+y+"px",
left:e.pageX+x+"px"
}).show("slow");
}).mouseout(function(e){//鼠標移開的時候
$("#tooltip").remove();
}).mousemove(function(e){//鼠標移動的時候
$("#tooltip").css({
top:e.pageY+y+"px",
left:e.pageX+x+"px"
}).show("slow");
})
});
</script>
</head>
<body>
<ul>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
<li><a href="02121.png" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="tooltip" ><img src="02121.png" /></a></li>
</ul>
<br/><br/><br/><br/>
<br/><br/><br/><br/>
</body>
</html>
以上這篇JavaScript通過mouseover()實現(xiàn)圖片變大效果的示例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
js調(diào)試工具console.log()方法查看js代碼的執(zhí)行情況
以往都是使用alert的方式查看js代碼的執(zhí)行情況,今天看到有朋友使用console.log函數(shù)打印輸出函數(shù),變量,對象,下邊就console.log的使用情況進行記錄2014-08-08
javascript AutoScroller 函數(shù)類
javascript AutoScroller 自動滾動類代碼,學習類的朋友可以參考下。2009-05-05
JavaScript 動態(tài)將數(shù)字金額轉(zhuǎn)化為中文大寫金額
JavaScript 將數(shù)字金額轉(zhuǎn)化為中文大寫金額的函數(shù)2009-05-05
JavaScript中改變this指向的三種方式總結(jié)
this?指向的值是可以通過手動方式去改變的,比如call、bind、apply方法,本文主要為大家介紹了這三種方式的具體實現(xiàn)步驟,需要的可以參考下2023-12-12
JavaScript基于DOM操作實現(xiàn)簡單的數(shù)學運算功能示例
這篇文章主要介紹了JavaScript基于DOM操作實現(xiàn)簡單的數(shù)學運算功能,涉及javascript節(jié)點操作、元素遍歷及數(shù)學運算相關(guān)操作技巧,需要的朋友可以參考下2017-01-01

