มิกซ์แอนิเมชั่น Sass โดยใช้การรวม

ฉันกำลังพยายามให้ตัวอย่างนี้ใช้งานได้ แต่ฉันไม่เห็นภาพเคลื่อนไหวใด ๆ เลย ฉันต้องการกระชับมิกซ์อินให้มากที่สุดเท่าที่จะเป็นไปได้ และใช้การรวมเพื่อพยายามรักษาแอนิเมชั่นให้มีประสิทธิภาพ

https://brandonbrule.github.io/scss-animation-keyframe-mixin/< /ก>

ซอของฉัน http://jsfiddle.net/knum7po2/1/

// CSS
.animation-slide-in-up{
  @include animation(0, 0.5s, animation-slide-in-up, ease);
}

.animation-slide-in-down{
  @include animation(0, 0.5s, animation-slide-in-down, ease);
}

.animation-slide-in-right{
  @include animation(0, 0.5s, animation-slide-in-right, ease);
}

.animation-slide-in-left{
  @include animation(0, 0.5s, animation-slide-in-left, ease);
}

.animation-slide-out-up{
  @include animation(0, 0.5s, animation-slide-out-up, ease);
}

.animation-slide-out-down{
  @include animation(0, 0.5s, animation-slide-out-down, ease);
}

.animation-slide-out-right{
  @include animation(0, 0.5s, animation-slide-out-right, ease);
}

.animation-slide-out-left{
  @include animation(0, 0.5s, animation-slide-out-left, ease);
}


@mixin keyframe ($animation_name) {
    @-webkit-keyframes $animation_name {
        @content;
    }

    @-moz-keyframes $animation_name {
        @content;
    }

    @-o-keyframes $animation_name {
        @content;
    }

    @keyframes $animation_name {
        @content;
    }
}

@mixin animation ($delay, $duration, $animation, $direction: forward, $fillmode: fowards) {
    -webkit-animation-delay: $delay;
    -webkit-animation-duration: $duration;
    -webkit-animation-name: $animation;
    -webkit-animation-fill-mode: $fillmode;
    -webkit-animation-direction: $direction;

    -moz-animation-delay: $delay;
    -moz-animation-duration: $duration;
    -moz-animation-name: $animation;
    -moz-animation-fill-mode: $fillmode;
    -moz-animation-direction: $direction;

    animation-delay: $delay;
    animation-duration: $duration;
    animation-name: $animation;
    animation-fill-mode: $fillmode;
    animation-direction: $direction;
}




// -- Slide Animations -- //

// Slide Out Top from Center
@include keyframe(animation-slide-out-up) {
    0% {
        transform: translate(0,0);
    }

    100% {
        transform: translate(0,-100%);
    }
}

@include keyframe(animation-slide-out-down) {
    0% {
        transform: translate(0,0);
    }

    100% {
        transform: translate(0,100%);
    }
}

// Slide Out Left from Center
@include keyframe(animation-slide-out-left) {
    0% {
        transform: translate(0,0);
    }

    100% {
        transform: translate(-100%,0);
    }
}

// Slide out Right from Center
@include keyframe(animation-slide-out-right) {
    0% {
        transform: translate(0,0);
    }

    100% {
        transform: translate(100%,0);
    }
}

@include keyframe(animation-slide-in-up) {
    0% {
        transform: translate(0,100%);
    }

    100% {
        transform: translate(0,0);
    }
}

@include keyframe(animation-slide-in-down) {
    0% {
        transform: translate(0,-100%);
    }

    100% {
        transform: translate(0,0);
    }
}

// Slide in Left to Center
@include keyframe(animation-slide-in-left) {
    0% {
        transform: translate(-100%,0);
    }

    100% {
        transform: translate(0,0);
    }
}

// Slide in Right to Center
@include keyframe(animation-slide-in-right) {
    0% {
        transform: translate(100%,0);
    }

    100% {
        transform: translate(0,0);
    }
}
<div class="animation-slide-in-up">c</div>
<div class="animation-slide-in-down">x</div>
<div class="animation-slide-in-right">x</div>
<div class="animation-slide-in-left">x</div>

<div class="animation-slide-out-up">x</div>
<div class="animation-slide-out-down">x</div>
<div class="animation-slide-out-right">x</div>
<div class="animation-slide-out-left">x</div>


person The Old County    schedule 14.12.2020    source แหล่งที่มา


คำตอบ (1)


ต่อไปนี้เป็นสองเหตุผลว่าทำไมคุณถึงไม่คอมไพล์:

  • @mixin มาก่อนเสมอ

ไม่มีการยกเรื่องไร้สาระ ดังนั้นให้แน่ใจว่าคุณใส่มิกซ์อินและตัวแปรเสมอก่อนที่จะอ้างอิงถึงพวกมัน

  • หากคุณต้องการใช้ตัวแปรกับตัวเลือก/ชื่อคุณสมบัติ คุณต้องใช้ interpolations(#{})

เปลี่ยน

@mixin keyframe ($animation_name) {
    @-webkit-keyframes $animation_name {
        @content;
    }
    
    // ...
}

to

@mixin keyframe ($animation_name) {
    @-webkit-keyframes #{$animation_name} {
        @content;
    }
    
    // ...
}

นี่คือซอคงที่: http://jsfiddle.net/hscbfeox/

person Hao Wu    schedule 14.12.2020
comment
ฉันยังไม่เห็นสิ่งที่เคลื่อนไหว? - person The Old County; 14.12.2020
comment
ลองคลิกที่ปุ่ม Run @TheOldCounty - person Hao Wu; 14.12.2020
comment
อ่า มันขยับตั้งแต่เริ่มต้น - ฉันแค่คิดว่าฉันกำลังดูหน้าเริ่มต้นอยู่ - person The Old County; 14.12.2020
comment
คุยโวยวาย -- บอกฉันหน่อยสิ -- ทำไมของของเขาถึงไม่รวมนั่นล่ะ? - person The Old County; 14.12.2020
comment
การยกอย่างคร่าว ๆ หมายถึงคำจำกัดความจะอยู่ด้านบนสุดเสมอ เช่น การยกใน JavaScript คุณสามารถอ้างถึงฟังก์ชันก่อนที่จะกำหนดได้ แต่ sass ไม่มีฟีเจอร์นั้น ดังนั้นคุณต้องใส่โค้ดคำจำกัดความของคุณก่อนที่จะอ้างอิง นี่คือคำตอบที่อธิบาย - person Hao Wu; 14.12.2020
comment
ฉันเข้าใจแล้ว - ฉันกำลังพยายามนำไปใช้กับตัวอย่างนี้ - jsfiddle.net/xpb90keq/3 พยายาม เพื่อให้รูปร่างจางลง - แต่ฉันต้องการล้างฟังก์ชันมิกซ์อินก่อน - person The Old County; 14.12.2020
comment
เพียงแค่ต้องรู้ว่ามันเป็นแนวปฏิบัติที่ดีที่จะใส่มิกซ์อินและตัวแปรทั้งหมดของคุณลงในไฟล์ sass/scss อื่นและ @import พวกมันก่อน หรือหากคุณใช้ไฟล์ sass/scss ไฟล์เดียว ให้วางไว้ที่ด้านบนเสมอ - person Hao Wu; 14.12.2020
comment
jsfiddle.net/5f712csm -- ฉันได้นำไปใช้แล้ว - แต่ฉันไม่เห็นว่ามันใช้งานได้ - ไม่มีที่สิ้นสุด ต้องเปิดใช่ไหม? - person The Old County; 14.12.2020
comment
jsfiddle.net/5f712csm/1 - ไม่มีอะไรทำงาน - แต่ฉันแน่ใจว่าฉันได้คัดลอกแล้ว ความคิดตลอด - person The Old County; 14.12.2020
comment
jsfiddle.net/zv2rc70d -- มี 1 รายการขยับขึ้น - แต่ทำเฉพาะตอนเริ่มต้นเท่านั้น -- กระตือรือร้นที่จะ ทำให้มันจางลงจากด้านล่าง ค่อยๆ จางลงเมื่อขึ้นไปด้านบน -- และทำซ้ำอย่างไม่มีสิ้นสุด - person The Old County; 14.12.2020
comment
ตรวจสอบอันนี้: jsfiddle.net/nsrte6g5 คุณลืมกำหนด bubble ความกว้างและความสูง นอกจากนี้ คุณต้องกำหนด animation-iteration-count ให้กับ infinite หากคุณต้องการให้แอนิเมชั่นวนซ้ำ - person Hao Wu; 14.12.2020
comment
นอกจากนี้ หากคุณต้องการถามคำถามอื่นเพิ่มเติม คุณควรถามคำถามอื่นแทน ความคิดเห็นไม่ใช่ที่ที่ดีที่จะทำเช่นนั้น - person Hao Wu; 14.12.2020
comment
stackoverflow.com/questions/65192163/ -- คำถามอยู่ที่นี่ - person The Old County; 14.12.2020
comment
ความกว้างและความสูงของฟองอากาศ -- ที่ไหน? อ่า ตัวอนุภาคเอง -- นั่นเป็นสาเหตุให้ความกว้าง/ความสูงขึ้นอยู่กับขนาดของไอคอนที่อยู่ข้างในใช่ไหม - person The Old County; 14.12.2020
comment
@TheOldCounty มันเป็น แต่คุณลืมกำหนด width และ height ให้กับ svg ที่อยู่ข้างในเช่นกัน หากคุณตรวจสอบองค์ประกอบ คุณจะเห็นว่า width และ height ทั้งหมดเป็น 0 - person Hao Wu; 14.12.2020
comment
jsfiddle.net/n139wod0/2 - person The Old County; 14.12.2020
comment
.magic-cloud .small .MuiSvgIcon-root { ขนาดตัวอักษร: 15px; } -- มี CSS หรือเปล่า? - person The Old County; 14.12.2020
comment
ฉันจะทำให้รูปร่างจางหายไปตั้งแต่เริ่มต้นได้อย่างไร - และไม่ใช่แค่ปรากฏในโซนสีแดง - เหมือนเริ่มต้นเป็นสีแดงและสิ้นสุดก่อนสีแดง - codesandbox.io/s/holy-tdd-57ov7?file=/src/MagicCloud.js - person The Old County; 14.12.2020