参照:Add zoom icon to images using CSS (and jQuery, of course)
CSSだけでも、ズームアイコンの表示・非表示切替を行うことはできますが、jQueryを使用することで、ズームアイコンの表示・非表示切替にアニメーション効果を付けることができます。
<!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" xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ja" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>イベント操作:相互作用:hoverの使用例 | jQuery</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ /* 例2 */ $("#gallery2 a").append("<span></span>"); $("#gallery2 a").hover(function(){ $(this).children("span").fadeIn(600); },function(){ $(this).children("span").fadeOut(200); }); }); </script> <!-- CSS --> <style type="text/css"> /* 例1 */ #gallery1 { width:100%; overflow:hidden;} #gallery1 a { position:relative; float:left; margin:5px;} #gallery1 a span { display:none; background-image:url("/content/img/icon/24/zoom.png"); background-repeat:no-repeat; width:48px; height:48px; position:absolute; left:15px; top:15px;} #gallery1 a:hover span { display:block;} #gallery1 img { border:solid 1px #999; padding:5px;} /* 例2 */ #gallery2 { width:100%; overflow:hidden;} #gallery2 a { position:relative; float:left; margin:5px;} #gallery2 a span { background-image:url("/content/img/icon/24/zoom.png"); background-repeat:no-repeat; width:48px; height:48px; display:none; position:absolute; left:15px; top:15px;} #gallery2 img { border:solid 1px #999; padding:5px;} </style> <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head> <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <h1>イベント操作:相互作用:hoverの使用例 | jQuery</h1> <h2>画像にマウスオーバーした時にズームアイコンを画像上に表示s</h2> <p>参照:<a href='http://www.jankoatwarpspeed.com/post/2009/04/06/Add-zoom-icon-to-images-using-CSS-and-jQuery.aspx'>Add zoom icon to images using CSS (and jQuery, of course)</a></p> <p>CSSだけでも、ズームアイコンの表示・非表示切替を行うことはできますが、jQueryを使用することで、ズームアイコンの表示・非表示切替にアニメーション効果を付けることができます。</p> <!-- CODE --> <div id="gallery1"> <h2>例1:CSSのみ</h2> <a href="http://www.flickr.com/photos/22559849@N06/3274514408/"> <span></span> <img src="http://farm4.static.flickr.com/3514/3274514408_1800118ded_m.jpg" alt="アボカド シーザーサラダ" /> </a> <a href="http://farm4.static.flickr.com/3509/3273696567_ebf4ed4381_m.jpg"> <span></span> <img src="http://farm4.static.flickr.com/3509/3273696567_ebf4ed4381_m.jpg" alt="アボカド刺" /> </a> <a href="http://www.flickr.com/photos/22559849@N06/3273696469/"> <span></span> <img src="http://farm4.static.flickr.com/3427/3273696469_aa2aaf5e89_m.jpg" alt="ベーコンとアボカドのピザ(トマトソース)" /> </a> </div><!-- #gallery1 --> <div id="gallery2"> <h2>例2:jQuery使用(アニメーション)</h2> <a href="http://www.flickr.com/photos/22559849@N06/3142429603/"> <img src="http://farm4.static.flickr.com/3214/3142429603_3b4ddd96a9_m.jpg" alt="イルミネーション@サザンテラス" /> </a> <a href="http://www.flickr.com/photos/22559849@N06/3143248598/"> <img src="http://farm4.static.flickr.com/3089/3143248598_018daa38eb_m.jpg" alt="イルミネーション@サザンテラス" /> </a> <a href="http://www.flickr.com/photos/22559849@N06/3142386073/"> <img src="http://farm4.static.flickr.com/3244/3142386073_87c62671a5_m.jpg" alt="イルミネーション@サザンテラス" /> </a> </div><!-- #gallery2 --> <!-- / CODE --> </div> </body> </html>