為什么我按照老師寫的程序,在chrome和IE上面寬度和高度只能變化到393呢?
<!DOCTYPE html>
<html lang="en">
<head>
? ?<meta charset="UTF-8">
? ?<title>任意值運動</title>
? ?<style>
body{
margin:0;
padding:0;
? ? ? ?}
div{
width:200px;
height:200px;
background: green;
margin:50px;
font-size:10px;
? ? ? ?}
? ?</style>
? ?<script>
window.onload = function () {
var oDiv1 = document.getElementById('div1');
var oDiv2 = document.getElementById('div2');
var oDiv3 = document.getElementById('div3');
oDiv1.onmouseover = function () {
startMove(this,'height',400);
? ? ? ? ? ?};
oDiv1.onmouseout = function () {
startMove(this,'height',200);
? ? ? ? ? ?};
oDiv2.onmouseover = function () {
startMove(this,'width',400);
? ? ? ? ? ?};
oDiv2.onmouseout = function () {
startMove(this,'width',200);
? ? ? ? ? ?};
oDiv3.onmouseover = function () {
startMove(this,'fontSize',50);
? ? ? ? ? ?};
oDiv3.onmouseout = function () {
startMove(this,'fontSize',10);
? ? ? ? ? ?};
? ? ? ?} ;
var iCount = 0;
function startMove(obj,attr,iTarget) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var iCur = parseInt(getStyle(obj,attr));
var speed = (iTarget - iCur) / 8;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if(iCur == iTarget){
clearInterval(obj.timer);
? ? ? ? ? ? ? ?}else{
obj.style[attr] = iCur + speed +'px';
? ? ? ? ? ? ? ?}
? ? ? ? ? ?},30);
? ? ? ?}
function getStyle(obj, attr) {
if(obj.currentStyle){
return obj.currentStyle[attr];
? ? ? ? ? ?}else{
return getComputedStyle(obj,false)[attr];
? ? ? ? ? ?}
? ? ? ?}
? ?</script>
</head>
<body>
? ?<div id = 'div1'></div>
? ?<div id = 'div2'></div>
? ?<div id = 'div3'>hello world</div>
</body>
</html>
2016-11-03
我把你的代碼運行后沒有出現(xiàn)你說的問題啊
2016-10-24
跟你一樣,坑
2016-10-03
你加上
`*{ margin:0; padding:0}` 試看