第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么實(shí)現(xiàn)不了同時(shí)運(yùn)動(dòng)

<!DOCTYPE html>
<html>
<head>
?? ?<meta charset="UTF-8">
?? ?<title>test</title>
?? ?<style>
?? ?*{
?? ??? ?margin:0;
?? ??? ?padding:0;
?? ?}
?? ?#ul1 li{
?? ??? ?width:150px;
?? ??? ?height:100px;
?? ??? ?margin-top: 20px;
?? ??? ?background: red;
?? ??? ?border:1px solid green;
?? ??? ?opacity: 0.8;
?? ??? ?filter:alpha(opacity=80);
?? ??? ?/*加上邊框后,會(huì)導(dǎo)致offsetwidth變寬*/
?? ??? ?/*position:relative;*/
?? ??? ?
?? ?}
?? ?</style>
</head>
<body>
?? ?<ul id="ul1">
?? ??? ?<li></li>
?? ??? ?<li></li>
?? ??? ?<li></li>
?? ?</ul>
?? ?<script>
?? ??? ?var ul1=document.getElementById("ul1");
?? ??? ?var lis=ul1.getElementsByTagName("li");
?? ??? ?//獲取非行間樣式
?? ??? ?function getStyle(obj,name){
?? ??? ??? ?if(obj.currentStyle){
?? ??? ??? ??? ?return obj.currentStyle[name];
?? ??? ??? ?}else{
?? ??? ??? ??? ?return getComputedStyle(obj,false)[name];
?? ??? ??? ?}
?? ??? ?}
//?? ??? ?for(var i=0;i<lis.length;i++){
?? ??? ??? ?//數(shù)組是對(duì)象,給對(duì)象設(shè)置一份屬性值;設(shè)置不同的數(shù)組的定時(shí)器,使多物體運(yùn)動(dòng)時(shí)相互不受影響
//?? ??? ??? ?lis[i].n=null;
???????? //鏈?zhǔn)竭\(yùn)動(dòng)
//?? ??? ??? ?lis[0].onmouseover=function(){
//?? ??? ??? ??? ?move(this,'opacity',30);
////?? ??? ??? ??? ?alert(1)
//?? ??? ??? ?}
//?? ??? ??? ?
//?? ??? ??? ?lis[0].onmouseout=function(){
//?? ??? ??? ??? ?move(this,'opacity',80);
//?? ??? ??? ?}
//?? ??? ?}
??????? //鏈?zhǔn)竭\(yùn)動(dòng)
//????? lis[1].onmouseover=function(){
//?? ??? ??? ??? ?move( lis[1],'height',260,function(){
//?? ??? ??? ??? ??? ?move(lis[1],'width',300,function(){
//?? ??? ??? ??? ??? ??? ?move(lis[1],'opacity',30)
//?? ??? ??? ??? ??? ?})
//?? ??? ??? ??? ?});
////?? ??? ??? ??? ?alert(1)
//?? ??? ??? ?}
//?? ??? ??? ?
//?? ??? ?lis[1].onmouseout=function(){
//?? ??? ??? ??? ?move(lis[1],'width',150,function(){
//?? ??? ??? ??? ??? ?move(lis[1],'height',100)
//?? ??? ??? ??? ?});
//?? ??? ??? ?}

?? //同時(shí)運(yùn)動(dòng)
????? lis[0].onmouseover=function(){
???? ??? ?move(lis[0],{'opacity':20,'width':300})
????? }
???? ?
?? ??? ?function move(obj, json,fn){
?? ??? ??? ?//清除與調(diào)用計(jì)時(shí)器
?? ??? ??? ?//attr是json內(nèi)的name
?? ??? ??? ?var flag=true;
?? ??? ??? ?for(var attr in json){
?? ??? ??? ?clearInterval(obj.n);
?? ??? ??? ?obj.n=setInterval(function(){
????????? //?? ?console.log(obj.offsetWidth)
?? ??? ? //當(dāng)有邊框時(shí)不能用offsetWidth,而要用clientwidth或者
???????? //是通過(guò)獲取非行間樣式的方法或的width(getStyles)
?????????????? var cur=0;
?????????????? //判斷是哪種類型
?????????????? if(attr=="opacity"){
?????????????? cur=parseFloat(getStyle(obj,attr))*100;
?????????????? }else{
????????????? ??? ?cur=parseInt(getStyle(obj,attr))
?????????????? }
?????????????? //計(jì)算速度
?? ??? ??? ??? ?var speed=(json[attr]-cur)/10;
?? ??? ??? ??? ?speed=speed>0?Math.ceil(speed):Math.floor(speed);
?? ??? ??? ??? ?//給對(duì)象賦值
?? ??? ??? ??? ?if(cur!=json[attr]){
?? ??? ??? ??? ??? ?flag=false;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?if(attr=="opacity"){
?? ??? ??? ??? ?obj.style.opacity=(cur+speed)/100;
?? ??? ??? ??? ?obj.style.filter="alpha(opacity:"+cur+speed+")"?? ?
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?else{
?? ??? ??? ??? ??? ??? ?obj.style[attr]=cur+speed+"px";
?? ??? ??? ??? ?}
?? ??? ??? ??? ?if(flag){
?? ??? ??? ??? ??? ?clearInterval(obj.n)
?? ??? ??? ??? ??? ?if(fn){
?? ??? ??? ??? ??? ??? ?fn();
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ?},17)
?? ??? ??? ?}
?? ??? ??? ?}
?? ?</script>
</body>
</html>



正在回答

1 回答

  1. var flag=true;? 及for(var attr in json) 應(yīng)該放在定時(shí)器n內(nèi), json的for循環(huán)之前

  2. if(flag){清除定時(shí)器和fn回調(diào)}應(yīng)該放在定時(shí)器n內(nèi), json的for循環(huán)之后

  3. 具體解釋可以參考<JS動(dòng)畫(huà)效果課程?6-2小節(jié)>的評(píng)論區(qū)討論,希望能幫到你

更改后的參考code如下(未貼上來(lái)的其他code不變):

????????function?move(obj,?json,fn){
????????????//清除與調(diào)用計(jì)時(shí)器
????????????//attr是json內(nèi)的name
????????????clearInterval(obj.n);
????????????obj.n=setInterval(function(){
????????????//?console.log(obj.offsetWidth)
????????????//?當(dāng)有邊框時(shí)不能用offsetWidth,而要用clientwidth或者
????????????//?是通過(guò)獲取非行間樣式的方法或的width(getStyles)
?????????????var?flag?=?true;
?????????????for?(var?attr?in?json)?{
?????????????????var?cur?=?0;
?????????????????//判斷是哪種類型
?????????????????if?(attr?==?"opacity")?{
?????????????????????cur?=?parseFloat(getStyle(obj,?attr))?*?100;
?????????????????}?else?{
?????????????????????cur?=?parseInt(getStyle(obj,?attr));
?????????????????}
?????????????????//計(jì)算速度
?????????????????var?speed?=?(json[attr]?-?cur)?/?10;
?????????????????speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed);
?????????????????//給對(duì)象賦值
?????????????????if?(cur?!=?json[attr])?{
?????????????????????flag?=?false;
?????????????????}
?????????????????if?(attr?==?"opacity")?{
?????????????????????obj.style.opacity?=?(cur?+?speed)?/?100;
?????????????????????obj.style.filter?=?"alpha(opacity:"?+?cur?+?speed?+?")";
?????????????????}?else?{
?????????????????????obj.style[attr]?=?cur?+?speed?+?"px";
?????????????????}
?????????????}
????????????if?(flag)?{
????????????????clearInterval(obj.n);
????????????????if?(fn)?{
????????????????????fn();
????????????????}
????????????}
????????????},17);
????????}
0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么實(shí)現(xiàn)不了同時(shí)運(yùn)動(dòng)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)