javascript美术馆改进版

本文通过一系列图片展示了作者一天早晨从起床到出门前的日常活动流程,包括起床、刷牙、洗脸和梳头等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image</title>
<style rel="stylesheet" type="text/css">
<!--
body{
	background:#666;
	margin:0;
	padding:0;
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:12px;
	color:#fff;
}

a:link,a:visited,a:active{
	text-decoration:none;
	color:#fff;
	font-size:12px;
}

a:hover{
	text-decoration:underline;
	color:#0cf;
	font-size:12px;
}

.content{
	width:400px;
	margin:0 auto;
}

ul{
	margin:0;
	padding:0;
	list-style-type:none;
	
}

li{
	margin-bottom:10px;
	float:left;
	padding-right:20px;
}
-->
</style>

<script language="javascript" type="text/javascript">

function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}
	else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function insertAfter(newElement,targetElement){
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement){
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

function preparePlaceholder(){
	if(!document.createElement) return false;
	if(!document.createTextNode) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("imagegallery")) return false;
	var placeholder = document.createElement("img");
	placeholder.setAttribute("id","placeholder");
	placeholder.setAttribute("src","http://ice-cream.iteye.com/upload/picture/pic/8572/bf42aa6e-fec4-31f1-9814-361234b93ca7.gif");
	placeholder.setAttribute("alt","a beautiful day's morning");
	var description = document.createElement("p");
	description.setAttribute("id","description");
	var desctext = document.createTextNode("Choose an image");
	description.appendChild(desctext);
	var gallery = document.getElementById("imagegallery");
	insertAfter(placeholder,gallery);
	insertAfter(description,placeholder);
}

function prepareGallery(){
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("imagegallery")) return false;
	var gallery = document.getElementById("imagegallery");
	var links = gallery.getElementsByTagName("a");
	for (var i=0;i<links.length;i++ ){
		links[i].onclick = function(){
			return showPic(this);
		}
	links[i].onkeypress = links[i].onclick;
	}
}

function showPic(whichpic){
	if (!document.getElementById("placeholder")) return true;
	var source = whichpic.getAttribute("href");
	var placeholder = document.getElementById("placeholder");
	if (placeholder.nodeName != "IMG") return true;
	placeholder.setAttribute("src",source);
	if (!document.getElementById("description")) return false;
	var text = whichpic.getAttribute("title")?
	whichpic.getAttribute("title"):"";
	var description = document.getElementById("description");
	if (description.firstChild.nodeType == 3){
		description.firstChild.nodeValue = text;
	}
	return false;
}

addLoadEvent(preparePlaceholder);
addLoadEvent(prepareGallery);

</script>
</head>
<body>
<div class="content">
<h1>One day morning</h1>
<ul id="imagegallery">
	<li><a href="http://ice-cream.iteye.com/upload/picture/pic/8580/727a3394-9931-3dd5-a91a-3d6939c17f6f.gif" title="One day morning,I first open my eyes and get up." onclick ="return showPic(this);" onkeypress="return showPic(this);">1.Get up</a></li>
	<li><a href="http://ice-cream.iteye.com/upload/picture/pic/8578/67a50c92-bb8f-35c1-ac42-b3ef20d7905d.gif" title="I come to the toilet to brush my teeth." onclick ="return showPic(this);" onkeypress="return showPic(this);">2.Brush teeth</a></li>
	<li><a href="http://ice-cream.iteye.com/upload/picture/pic/8576/63f36ddd-424d-3342-9194-5a056b6ca509.gif" title="Then wash my face to become sober." onclick ="return showPic(this);" onkeypress="return showPic(this);">3.Wash face</a></li>
	<li><a href="http://ice-cream.iteye.com/upload/picture/pic/8574/87f1dd65-fd7e-362f-8861-ee53ef4e0314.gif" title="Next to mirror to comb my hair,and over" onclick ="return showPic(this);" onkeypress="return showPic(this);">4.Comb hair</a></li>
</ul>
</div>
</body>
</html>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值