リンク要素をマウスオーバー時に画像表示するのデモページ「URLプレビュー」

URLプレビュー

CSS Lecture (キャンプションなし)

CSS Lecture (キャンプションあり)

XHTML

<p><a href="http://www.css-lecture.com/" class="screenshot" rel="image/css-lecture.jpg">CSS Lecture</a> (キャンプションなし)</p>
<p><a href="http://www.css-lecture.com/" class="screenshot" rel="image/css-lecture.jpg" title="CSS Lecture">CSS Lecture</a> (キャンプションあり)</p>

CSS

#screenshot{
	position: absolute;
	border: 3px solid #333;
	background: #444;
	padding: 5px;
	display: none;
	color: #FFF;
    text-align: center;
}

Javascript

this.screenshotPreview = 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.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "
" + this.t : ""; $("body").append("

url preview"+ c +"

"); $("#screenshot") .css("top",(e.pageY - xOffset) + "px") .css("left",(e.pageX + yOffset) + "px") .fadeIn("fast"); }, function(){ this.title = this.t; $("#screenshot").remove(); }); $("a.screenshot").mousemove(function(e){ $("#screenshot") .css("top",(e.pageY - xOffset) + "px") .css("left",(e.pageX + yOffset) + "px"); }); }; // starting the script on page load $(document).ready(function(){ screenshotPreview(); });
Copyright © 2009 CSS Lecture All rights reserved.