<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>Title</title>
????<style>
?#show?{width:?100px;height:?200px;?background:?#ccc;?display:?none;}
?#you{
?width:?300px;
?height:?300px;
?background:?red;
????????}
????</style>
????<script>
?window.onload?=?function?()?{
?//根據(jù)ID返回dom元素
?var?$?=?function(id){return?document.getElementById(id);}
?//返回dom元素的當(dāng)前某css值
?var?getCss?=?function(obj,name){
?if(obj.currentStyle)?{//for?ie?;
?return?obj.currentStyle[name];
????????????????}else?{?//?for?ff;
?var?style?=?document.defaultView.getComputedStyle(obj,null);
?return?style[name];
????????????????}
????????????}
?var?show?=?function(obj,speed,fn){
?obj?=?$(obj);
?if?(!speed)?{
?obj.style.display?=?'block';
?return;
????????????????}
?var?initH?=?0?,?initW?=?0;
?//獲取dom的寬與高
?var?oWidth?=?getCss(obj,'width').replace('px',''),?oHeight?=?getCss(obj,'height').replace('px','');
?//每次dom的遞減數(shù)(等比例)
?var?wcut?=?2*(+oWidth.replace('px','')?/?+oHeight.replace('px','')),hcut?=20;
?//處理動(dòng)畫函數(shù)
?var?process?=?function(){
?obj.style.overflow?=?'hidden';
?obj.style.display?=?'block';
?initW?=?(initW+wcut)?>?oWidth???oWidth?:?initW+wcut;
?initH?=?(initH+hcut)?>?oHeight???oHeight?:?initH+hcut;
?//判斷是否減完了
?if(initW?!==?oWidth?||?initH?!==?oHeight)?{
?//obj.style.width?=?initW+'px';
?obj.style.height?=?initH+'px';
?setTimeout(function(){process();},speed);
????????????????????}else?{
?//加完后,設(shè)置屬性為顯示以及原本dom的寬與高;
????????????????????????//obj.style.width?=?oWidth+'px';
?obj.style.height?=?oHeight+'px';
?if(fn){
?fn();
????????????????????????}
????????????????????}
????????????????}
?process();
????????????}
?show('you',30,function?()?{
?show('show',30)
????????????});
????????}
????</script>
</head>
<body>
<div?id="show"></div>
????<div?id="you"></div>
</body>
</html>因?yàn)槭切率?,從網(wǎng)上找到了這個(gè),但是這個(gè)不能設(shè)置obj的高或者寬變化,fn是我自己加的,但是發(fā)現(xiàn)第一次運(yùn)動(dòng)完以后要好長(zhǎng)時(shí)間才完成之后的運(yùn)動(dòng)。請(qǐng)高手幫我改改。
?求大神幫忙完善框架
慕九州7009252
2017-01-10 15:21:00