亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么這個程序將函數getStyle和startMove封裝在1個js文件里,透明度運行顯示不正常,而在一個html文件就能正常運行呢?

function getStyle(obj,attr){

? ? if(obj.currentStyle){

? ? return obj.currentStyle[attr];

? ? }else{

? ? return getComputedStyle(obj,false)[attr];

? ? }

}

function startMove(obj,attr,goal){

? ? ?clearInterval(obj.timer);

? ? ?obj.timer=setInterval(function(){

? ? ? var icce=0;

? ? ? if(attr=='opacity'){

? ? ? ? ?icce=Math.round(parseFloat(getStyle(obj,attr))*100);

? ? ? }else{

? ? ? icce=parseInt(getStyle(obj,attr));

? ? ? ? }

? ? ? var speed=(goal-icce)/8;

? ? ? speed=speed>0?Math.ceil(speed):Math.floor(speed);

? ? ? if (icce==goal){

? ? ? clearInterval(obj.timer);

? ? ? }else{

? ? ? if(attr=='opacity'){

? ? ? obj.style.filer='alpha(opacity:'+(icce+speed)+')';

? ? ? obj.style.opacity=(icce+speed)/100;

? ? ? }else{

? ? ? obj.style[attr]=icce+speed+'px';

? ? ? }

? ? ? }

? ? ?},30)

}


正在回答

3 回答

aLi.onmouseover=function(){

? startMove(this,'width',600);


}

ali.onmouseout=function(){

startMove(this,'opacity',90);


mouseover改變寬度,mouseout改變透明度,要完美顯示,應該還需要再加定時器吧。

0 回復 有任何疑惑可以回復我~

合到一起就能完美運行顯示,這是為什么

0 回復 有任何疑惑可以回復我~

<!DOCTYPE html>

<html>

<head>

<title></title>

<style type="text/css">

? ? ?ul,li{

? ? ? list-style: none;

? ? ?}

? ? ?li{

? ? ? ? width:400px;

? ? ? ? height: 200px;

? ? ? ? background: green; ? ? ?

? ? ? ? border-radius: 10px;

? ? ? ? border: 4px solid #111;

? ? ? ? filter: alpha(opacity:30);

? ? ? ? opacity: 0.3;

? ? ?}

</style>

<script src="js/move.js"></script>

<script>

window.onload=function(){

var aLi=document.getElementById('ali');

aLi.onmouseover=function(){

? startMove(this,'width',600);


}

ali.onmouseout=function(){

startMove(this,'opacity',90);

}

}

</script>

</head>

<body>

? <ul>

? <li id="ali"></li>

? </ul>

</body>

</html>

這個是與之相關的html

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么這個程序將函數getStyle和startMove封裝在1個js文件里,透明度運行顯示不正常,而在一個html文件就能正常運行呢?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號