アットウィキロゴ

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-Style-Type" content="text/css" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<title>sample2</title>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
		<script type="text/javascript">
$(function(){
	$("img.rollover").mouseover(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	}).mouseout(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).each(function(){
		$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	});
});
		</script>
		<style type="text/css">
li{
	display:inline;
	list-style-type:none;
}
img{
	border:none;
}
		</style>
	</head>
	<body>
		<ul>
			<li><a href="#"><img src="images/jquery.jpg" alt="jQuery" class="rollover" /></a></li><!--
			--><li><a href="#"><img src="images/javascript.jpg" alt="javascript" class="rollover" /></a></li><!--
			--><li><a href="#"><img src="images/css.jpg" alt="CSS" class="rollover" /></a></li><!--
			--><li><a href="#"><img src="images/html.jpg" alt="HTML" class="rollover" /></a></li>
		</ul>
	</body>
</html>
最終更新:2012年05月23日 23:45