<ul> <li><a href="image/001.jpg" class="preview"><img src="image/001.jpg" alt="サンプル画像" width="150" /></a></li> <li><a href="image/002.jpg" class="preview"><img src="image/002.jpg" alt="サンプル画像" width="150" /></a></li> <li><a href="image/003.jpg" class="preview"><img src="image/003.jpg" alt="サンプル画像" width="150" /></a></li> <li><a href="image/004.jpg" class="preview"><img src="image/004.jpg" alt="サンプル画像" width="150" /></a></li> </ul>
#preview{
position: absolute;
border: 3px solid #333;
background: #444;
padding: 5px;
display: none;
color: #FFF;
text-align: center;
}
<ul> <li><a href="image/001.jpg" class="preview" title="サンプル画像 1"><img src="image/001.jpg" alt="サンプル画像" width="150" /></a></li> <li><a href="image/002.jpg" class="preview" title="サンプル画像 2"><img src="image/002.jpg" alt="サンプル画像" width="150" /></a></li> <li><a href="image/003.jpg" class="preview" title="サンプル画像 3"><img src="image/003.jpg" alt="サンプル画像" width="150" /></a></li> <li><a href="image/004.jpg" class="preview" title="サンプル画像 4"><img src="image/004.jpg" alt="サンプル画像" width="150" /></a></li> </ul>
#preview{
position: absolute;
border: 3px solid #333;
background: #444;
padding: 5px;
display: none;
color: #FFF;
text-align: center;
}
this.imagePreview = function(){
/* CONFIG */
xOffset = 10;
yOffset = 30;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$("a.preview").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "
" + this.t : "";
$("body").append("
"+ c +"
");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#preview").remove();
});
$("a.preview").mousemove(function(e){
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
// starting the script on page load
$(document).ready(function(){
imagePreview();
});