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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Vue.js 中的二維角色動畫,setTimeout 問題

Vue.js 中的二維角色動畫,setTimeout 問題

一只斗牛犬 2023-06-15 09:52:09
我找到了一種在 Vue.js 中創(chuàng)建動畫的新方法 - 2D 角色進(jìn)展:您將在特定時間移動該圖片中的每個角色。解決方案:你會看到角色在移動。我創(chuàng)造了我自己的角色。之后我想改變這個角色的動畫numTotal > 0。正是我想要做的:我的主要動畫被調(diào)用idle,當(dāng)numTotal > 0想要將動畫更改為時angry,2 秒后動畫應(yīng)該切換回我的動畫idle查看.js<div?class="character"?:style="inlineStyle"></div>數(shù)據(jù)data() {? ? ? return {? ? ?? ? ? ? ? animationDelay: 2000,? ? ? ? ? angry: 'animation-name: angry',? ? ? ? ? idle: 'animation-name: idle',? ? ? ? ? currentAnimation: null,? ? ? ? ? afterAnimation: null,? ? ? ? ? animation: null,? ? ? }? ? },計算的computed: {? ? ? ? inlineStyle() {? ? ? ? ? ? if (this.numTotal > 0) {? ? ? ? ? ? ? ? this.updateAnimation(this.animation, this.angry, this.idle)? ? ? ? ? ? ? ? return this.animation? ? ? ? ? ? } else {? ? ? ? ? ? ? ? this.animation = this.idle? ? ? ? ? ? ? ? return this.animation? ? ? ? ? ? }? ? ? ? }? ? },方法? ? methods: {? ? ? ? updateAnimation(animation, currentAnimation, afterAnimation){? ? ? ? ? ? animation = currentAnimation? ? ? ? ? ? setTimeout(() => {? ? ? ? ? ? ? ? animation = afterAnimation? ? ? ? ? ? }, 500)? ? ? ? },風(fēng)格.character {? ? background-image: url("http://huwe_final.test/images/character-animation.png?7b1c86288eb21d80e5981e0693e08d5e");? ? position: absolute;? ? z-index: 100;? ? width: 93%;? ? height: 747px;? ? margin-left: 3px;;? ? animation-iteration-count: infinite;? ? animation-timing-function: steps(24);? ? animation-duration: 1.2s;}@keyframes idle {? ? from { background-position: 0 0; }? ? to { background-position: -11782px 0; }}@keyframes angry {? ? from { background-position: 0 745px; }? ? to { background-position: -11782px 745px; }}我遇到的問題是,setTimeout即使我在控制臺動畫中編寫時我也無法正常工作 -console.log(animation)我看到animation已經(jīng)更改為angry,但在網(wǎng)站上動畫仍然存在idle有誰知道如何解決setTimeout?感謝您的任何幫助!
查看完整描述

1 回答

?
侃侃無極

TA貢獻(xiàn)2051條經(jīng)驗 獲得超10個贊

我不確定,你的代碼片段有什么問題,因為你刪除的越來越多,我看不到任何錯誤。


但這應(yīng)該絕對有效。請參閱我的最小示例:


<html>


<head>

    <script src="https://unpkg.com/vue"></script>

    <style>

        html,

        body {

            height: 100%;

        }


        .red {

            background-color: red;

        }


        .blue {

            background-color: blue !important;

        }


        .green {

            background-color: green !important;

        }

    </style>

</head>


<body>

    <div id="example">

        <div id="bar" v-bind:class="animation">

            {{ hello }}

        </div>

    </div>

    <script>

        new Vue({

            el: '#example',

            data() {

                return {

                    hello: "background-div",

                    animation: "green"

                }

            },

            methods: {

                gainAttention(newVal) {


                    let last = this.animation;

                    this.animation = newVal;


                    setTimeout(() => {

                        this.animation = last;

                    }, 1000);


                }

            },

            mounted() {


                setTimeout(() => {

                    this.gainAttention("red");

                }, 3000);


                setTimeout(() => {

                    this.gainAttention("blue");

                }, 5000)


            }

        })

    </script>

</body>


</html>


如果您發(fā)布動畫/css,我會為您將它們放在一起。


查看完整回答
反對 回復(fù) 2023-06-15
  • 1 回答
  • 0 關(guān)注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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