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

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

透明度沒有改變

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style>

? ? *{

? ? ?margin: 0px;

? ? ?padding: 0px;

? ? }

? ? #div1{

? ? ?width: 200px;

? ? ?height: 180px;

? ? ?background: red;

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

? ? ?opacity: 0.3;

? ? }

</style>

<script>

window.noload=function(){

var odiv=Document.getElementById('div1');

odiv.onmouseover=function(){

starmove(100);

}

odiv.onmouseout=function(){

starmove(30);

}

}

? ? ? ? var timer = null;

? ? ? ? var alpha=30;

function starmove(iTarget){

var odiv = Document.getElementById('div1');

clearInterval(timer);

timer = setInterval(function(){

var speed=0;

if (alpha>iTarget) {

speed=-10;

}else{

speed=10;

}

if (alpha==iTarget){

clearInterval(timer);

}else{

alpha+=speed;

// odiv.style.filter='alpha(opacity:'+alpha+')';

odiv.style.filter = "alpha(opacity:‘+alpha+')";?

? ? ? ? ? ? ? ? ? ? odiv.style.opacity = alpha/100;

}

},30)

}

</script>

</head>

<body>

<div id="div1"></div>

</body>

</html>


正在回答

5 回答

整體沒問題,但里面的小錯誤太多了,這是給你修改后的代碼,自己去對照找一下錯誤吧。

<!DOCTYPE html>

<html>

<head>

?? ?<meta charset="UTF-8">

?? ?<title>Document</title>

?? ?<style>

??? *{

???? margin: 0px;

???? padding: 0px;

??? }

??? #div1{

???? width: 200px;

???? height: 180px;

???? background: red;

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

???? opacity: 0.3;

??? }

</style>

?? ?<script>

window.onload=function(){

var odiv=document.getElementById('div1');

odiv.onmouseover=function(){

starmove(100);

}

odiv.onmouseout=function(){

starmove(30);

}

}

??????? var timer = null;

??????? var alpha=30;

function starmove(iTarget){

var odiv = document.getElementById('div1');


clearInterval(timer);

timer = setInterval(function(){

var speed=0;

if (alpha>iTarget) {

speed=-10;

}else{

speed=10;

}

if (alpha==iTarget){

clearInterval(timer);

}else{

alpha+=speed;
console.log(alpha);

// odiv.style.filter='alpha(opacity:'+alpha+')';

odiv.style.filter = "alpha(opacity:'+alpha+')";

??????????????????? odiv.style.opacity = alpha/100;

}

},30)

}

</script>

</head>

<body>

?? ?<div id="div1"></div>

</body>

</html>

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

man豪 提問者

非常感謝!直接告訴我哪里錯就好了,找半天
2016-04-12 回復 有任何疑惑可以回復我~

少了也不好,多了也不好,少了改的時候容易出錯,多了看著比較繁瑣if,,

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

1 ?window.noload=function(){ ?//把noload改成onload

2?var odiv = Document.getElementById('div1'); //把Document改成document

3?odiv.style.filter = "alpha(opacity:‘+alpha+')"; //把‘ 改成 ” ?或把“ 改成 ’

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

有三個小錯誤,都是拼寫問題,window.onload你寫成了 window.noload; 還有兩處 Document.getElementById的‘D’不應該大寫,應該是document.getElementById。。這三處拼寫改了,應該就對了

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

<!doctype html>

<html>


<head>

? ? <meta charset="UTF-8">

? ? <title></title>


? ? <style>

? ? * {

? ? ? ? padding: 0;

? ? ? ? margin: 0;

? ? }

? ? div {

? ? ?background: blue;

? ? ?width: 200px;

? ? ?height: 200px;

? ? ?position: relative;

? ? ?left:0px;

? ? ?top:100px;

filter:alpha(opacity:30);

opacity:0.3;

? ? }

? ??

? ? </style>

? ??

</head>

<body>

? ? <div id="div1">

? ? </div>

</body>

<script type="text/javascript">

? window.onload = function(){

? ?var oDiv = document.getElementById("div1");

? ?oDiv.onmouseover = function(){

? ?startMove(100);

? ?}

? ?oDiv.onmouseout = function(){

? ?startMove(30);

? ?}

? }?

? var timer = null;//可有可無

? var alpha = 30;

? var speed = 0;

? ?function startMove(iTarget){

? ? clearInterval(timer);

if(alpha > iTarget) {

? ?speed = -10;

}else{

speed = 10;

}

? ? var oDiv = document.getElementById("div1");

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

? if(alpha == iTarget) {

? ? ? ? ?clearInterval(timer);

? ? ? ? }

? ? ? ? else {

alpha += speed;

oDiv.style.filter = "alpha(opacity:"+alpha+")";

? ? ? ? oDiv.style.opacity = alpha/100;

}

? ? ? ? },30)

? ? }

? ??

? ? </script>

</html>


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

舉報

0/150
提交
取消
JS動畫效果
  • 參與學習       113918    人
  • 解答問題       1502    個

通過本課程JS動畫的學習,從簡單動畫開始,逐步深入各種動畫框架封裝

進入課程

透明度沒有改變

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

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

幫助反饋 APP下載

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

公眾號

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