課程
/前端開發(fā)
/JavaScript
/JS動畫效果
請問JS部分應(yīng)該怎么改?
2016-09-25
源自:JS動畫效果 4-1
正在回答
<!doctype html><html>?<head>? <meta charset="UTF-8">? <meta name="Generator" content="EditPlus?">? <meta name="Author" content="">? <meta name="Keywords" content="">? <meta name="Description" content="">? <title>Document</title>? <style type="text/css">?? ? * {?? ??? ?margin:0;?? ??? ?padding:0;?? ?}?? ? ul li{?? ??? ?width:200px;?? ??? ?height:100px;?? ??? ?background:yellow;?? ??? ?list-style:none;?? ??? ?margin-top:20px;?? ??? ?filter:alpha(opacity:30);?? ??? ?opacity:0.3;?? ?}? </style>? <script type="text/javascript">?? ?window.onload=function(){?? ??? ?var lis=document.getElementsByTagName("li");?? ??? ?//var timer=null;?? ??? ?for(var i=0;i<lis.length;i++){?? ??? ??? ?lis[i].alpha=30;?? ??? ??? ?lis[i].timer=null;?? ??? ??? ?lis[i].onmouseover=function(){?? ??? ??? ??? ?showMove(this,400,100);?? ??? ??? ?}?? ??? ??? ?lis[i].onmouseout=function(){?? ??? ??? ??? ?showMove(this,200,30);?? ??? ??? ?}?? ??? ?}?? ??? ?function showMove(obj,target1,target2){?? ??? ??? ?clearInterval(obj.timer);?? ??? ??? ?obj.timer=setInterval(function(){?? ??? ??? ??? ?var sheed=(target1-obj.offsetWidth)/10;?? ??? ??? ??? ?if(sheed>0){?? ??? ??? ??? ??? ?sheed=Math.ceil(sheed);?? ??? ??? ??? ?}else {?? ??? ??? ??? ??? ?sheed=Math.floor(sheed);?? ??? ??? ??? ?}?? ??? ??? ??? ?var sheed2=0;?? ??? ??? ??? ?if(obj.alpha>target2){?? ??? ??? ??? ??? ?sheed2=-5;?? ??? ??? ??? ?}else{?? ??? ??? ??? ??? ?sheed2=5?? ??? ??? ??? ?}?? ??? ??? ??? ?if(obj.alpha == target2 && target1 == obj.offsetWidth){?? ??? ??? ??? ??? ?clearInterval(obj.timer);?? ??? ??? ??? ?}else{?? ??? ??? ??? ??? ?obj.alpha+=sheed2;?? ??? ??? ??? ??? ?obj.style.filter="alpha(opacity:"+obj.alpha+")";?? ??? ??? ??? ??? ?obj.style.opacity=obj.alpha/100;?? ??? ??? ??? ??? ?obj.style.width=obj.offsetWidth+sheed+"px";?? ??? ??? ??? ?}?? ??? ??? ?},30)?? ??? ?}?? ?}? </script>?</head>?<body>? <ul>?? ?<li></li>?? ?<li></li>?? ?<li></li>? </ul>?</body></html>
最后一句,obj.style.opacity=obj.alpha/10改為obj.style.opacity=obj.alpha/100,試試.我的代碼與你的結(jié)構(gòu)類似,兩種效果都出來了
你的obj.alpha沒有定義
沒看懂你透明度是怎么個(gè)變化的!1
舉報(bào)
通過本課程JS動畫的學(xué)習(xí),從簡單動畫開始,逐步深入各種動畫框架封裝
2 回答我想讓物體運(yùn)動和透明度同時(shí)實(shí)現(xiàn),但是不是我想要的那種效果,哪位大神幫忙看一下
1 回答在多個(gè)物體透明度動畫里
2 回答多物體改變是單物體運(yùn)動,各路大神看下錯(cuò)了那
1 回答多物體鏈?zhǔn)竭\(yùn)動,變形可以,透明度變不了
2 回答跪求怎么實(shí)現(xiàn)物體移動和透明度同時(shí)變化???
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-11-04
<!doctype html>
<html>
?<head>
? <meta charset="UTF-8">
? <meta name="Generator" content="EditPlus?">
? <meta name="Author" content="">
? <meta name="Keywords" content="">
? <meta name="Description" content="">
? <title>Document</title>
? <style type="text/css">
?? ? * {
?? ??? ?margin:0;
?? ??? ?padding:0;
?? ?}
?? ? ul li{
?? ??? ?width:200px;
?? ??? ?height:100px;
?? ??? ?background:yellow;
?? ??? ?list-style:none;
?? ??? ?margin-top:20px;
?? ??? ?filter:alpha(opacity:30);
?? ??? ?opacity:0.3;
?? ?}
? </style>
? <script type="text/javascript">
?? ?window.onload=function(){
?? ??? ?var lis=document.getElementsByTagName("li");
?? ??? ?//var timer=null;
?? ??? ?for(var i=0;i<lis.length;i++){
?? ??? ??? ?lis[i].alpha=30;
?? ??? ??? ?lis[i].timer=null;
?? ??? ??? ?lis[i].onmouseover=function(){
?? ??? ??? ??? ?showMove(this,400,100);
?? ??? ??? ?}
?? ??? ??? ?lis[i].onmouseout=function(){
?? ??? ??? ??? ?showMove(this,200,30);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?function showMove(obj,target1,target2){
?? ??? ??? ?clearInterval(obj.timer);
?? ??? ??? ?obj.timer=setInterval(function(){
?? ??? ??? ??? ?var sheed=(target1-obj.offsetWidth)/10;
?? ??? ??? ??? ?if(sheed>0){
?? ??? ??? ??? ??? ?sheed=Math.ceil(sheed);
?? ??? ??? ??? ?}else {
?? ??? ??? ??? ??? ?sheed=Math.floor(sheed);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?var sheed2=0;
?? ??? ??? ??? ?if(obj.alpha>target2){
?? ??? ??? ??? ??? ?sheed2=-5;
?? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ?sheed2=5
?? ??? ??? ??? ?}
?? ??? ??? ??? ?if(obj.alpha == target2 && target1 == obj.offsetWidth){
?? ??? ??? ??? ??? ?clearInterval(obj.timer);
?? ??? ??? ??? ?}else{
?? ??? ??? ??? ??? ?obj.alpha+=sheed2;
?? ??? ??? ??? ??? ?obj.style.filter="alpha(opacity:"+obj.alpha+")";
?? ??? ??? ??? ??? ?obj.style.opacity=obj.alpha/100;
?? ??? ??? ??? ??? ?obj.style.width=obj.offsetWidth+sheed+"px";
?? ??? ??? ??? ?}
?? ??? ??? ?},30)
?? ??? ?}
?? ?}
? </script>
?</head>
?<body>
? <ul>
?? ?<li></li>
?? ?<li></li>
?? ?<li></li>
? </ul>
?</body>
</html>
2016-09-26
最后一句,obj.style.opacity=obj.alpha/10改為obj.style.opacity=obj.alpha/100,試試.我的代碼與你的結(jié)構(gòu)類似,兩種效果都出來了
2016-09-26
你的obj.alpha沒有定義
2016-09-25
沒看懂你透明度是怎么個(gè)變化的!1