<!doctype?html>
<html>
<head>
<title>獲取樣式</title>
<meta??charset="UTF-8">
<!--<link?rel="stylesheet"?type="text/css"?href="CSS/style.css">
<script?type="text/javascript"?src="Js/script.js"></script>-->
</head>
<body>
<div?style="width:300px;margin:?auto;">
<img?src="images/heaven.png"?id="myImages">
</div>
<script?type="text/javascript">
window.onload=function(){
var?oImg=document.getElementById('myImages');
oImg.onclick=function(){
alert("你好!");
maxFun();
}
}
var?oImg=document.getElementById('myImages');
//定義放大函數(shù)
var?maxwidth=oImg.width*2;
var?maxheight=oImg.height*2;
function?maxFun(){
var?endwidth=oImg.width*1.3;
var?endheight=oImg.height*1.3;
var?maxTimer=setInterval(function(){
if?(oImg.width<endwidth)?{
if?(oImg.width<maxwidth)?{
oImg.width=oImg.width*1.05;
????oImg.height=oImg.height*1.05;
}?else{
clearInterval(maxTimer);
}
????}else{
???? clearInterval(maxTimer);
????}
},20);
}
</script>
</body>
</html>
2016-03-26
將window.onload方法的括號放最后面,即包裹住所有就可以了