<script>
????????//dom加載完才執(zhí)行以下代碼
????????window.onload=function(){
????????????????//取得a標(biāo)簽數(shù)據(jù)
????????????????var?atag?=?document.getElementsByTagName("a");
????????????????for(var?i=0;?i<?atag.length;i++)?{
????????????????????????/**鼠標(biāo)移入**/
????????????????????????atag[i].onmouseover=function(){
????????????????????????????????//先清空
????????????????????????????????clearInterval(this.time);
????????????????????????????????//獲得當(dāng)前的this對(duì)象
????????????????????????????????var?thisPara?=?this;
????????????????????????????????thisPara.time=setInterval(function(){
????????????????????????????????thisPara.style.width?=?thisPara.offsetWidth?+?8?+?"px";
????????????????????????????????if(thisPara.offsetWidth?>?120){
????????????????????????????????????????clearInterval(thisPara.time);
????????????????????????????????}
????????????????????????},30);
????????????????};
????????????????????????/**鼠標(biāo)移出**/
????????????????????????atag[i].onmouseout=function(){
????????????????????????????????//先清空
????????????????????????????????clearInterval(this.time);????????????????????????
????????????????????????????????var?thisPara?=?this;
????????????????????????????????setInterval(function(){
????????????????????????????????????????thisPara.style.width?=?thisPara.offsetWidth?-?8?+"px";
????????????????????????????????????????if(thisPara.offsetWidth?<?80){
????????????????????????????????????????????????thisPara.style.width?=?"80px";
????????????????????????????????????????????????clearInterval(thisPara.time);
????????????????????????????????????????}
????????????????????????????????},30)
????????????????????????};
????????????????}
????????}
</script>
2016-06-20
你設(shè)置鼠標(biāo)移除動(dòng)畫setInterval前面沒有用thisPara.time接收。導(dǎo)致clearInterval的時(shí)候參數(shù)undefined。
2016-06-21
@? 有一絲夢(mèng)想 ?非常感謝,自己的代碼就是不容易檢查出來!