color shifting SVG LOGO

Step 1

Assign a class to your SVG code embed.

For this project the class will be "color-logo"

Step 2

In the variables panel, establish the color sets for your logo's animation sequence.

Be sure to include the original logo colors in these sets as well.

This project has 4 color sets, including the original logo colors (color-set-1)

Step 3

Create a set of base logo color variables and link them to the original color set.

In this case the base colors were in color-set-1

Step 4

Copy the variable CSS from your base logo color set and link it paste it to the appropriate fill in your SVG.

Step 5

In a new code embed and define custom classes for each color set you wish to cycle through.

Use the base logo CSS variable, like 'logo-base--color-1', for each color. Removing the 'var()' and link it to the color set.

<style>
   
.color-set-1{
    --logo-base--color-1:var(--color-set-1--color-1);
    --logo-base--color-2:var(--color-set-1--color-2);
    --logo-base--color-3:var(--color-set-1--color-3);
}
.color-set-2{
    --logo-base--color-1:var(--color-set-2--color-1);
    --logo-base--color-2:var(--color-set-2--color-2);
    --logo-base--color-3:var(--color-set-2--color-3);
}
.color-set-3{
    --logo-base--color-1:var(--color-set-3--color-1);
    --logo-base--color-2:var(--color-set-3--color-2);
    --logo-base--color-3:var(--color-set-3--color-3);
}
.color-set-4{
    --logo-base--color-1:var(--color-set-4--color-1);
    --logo-base--color-2:var(--color-set-4--color-2);
    --logo-base--color-3:var(--color-set-4--color-3);
}
</style>

Step 6

Add the following code to enable smooth color transitions, replacing "color-logo" with your class from Step 1.

.color-logo svg path {
	transition: fill 3s ease-in-out;
}

This will enable the fill to transition smoothly between colors.

You can modify the timing by adjusting the '3' to your preference.

Step 7

Copy and paste code into the before </body> tag.

Remember to change the '.color-logo' to the same class in step 1.

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const containers = document.querySelectorAll('.color-logo');
    const colorClasses = ['color-set-1', 'color-set-2', 'color-set-3', 'color-set-4'];
    let currentSet = 0;

    function updateColors() {
      containers.forEach(container => {
        container.classList.remove(...colorClasses);

        container.classList.add(colorClasses[currentSet]);
      });

      currentSet = (currentSet + 1) % colorClasses.length;

      // Next update after 5 seconds (3s transition + 2s pause)
      setTimeout(pauseBeforeNext, 3000);
    }

    // 2s pause before next color set update
    function pauseBeforeNext() {
      setTimeout(updateColors, 2000);
    }
    pauseBeforeNext();
  });
</script>
Add more color sets by updating 'const colorClasses = ['color-set-1', 'color-set-2', 'color-set-3', 'color-set-4'];' with new class names matching those in Step 5.
Adjust animation duration by modifying 'setTimeout(pauseBeforeNext, 3000);' and change color transition pauses with 'setTimeout(updateColors, 2000);'.

Step 1

กำหนดคลาสให้กับโค้ด SVG ที่คุณฝังไว้เพิ่มคลาส

เช่น .color-logo ลงในแท็ก <svg> หรือคอนเทนเนอร์ของ SVG ที่คุณใช้งาน

Step 2

ในแผงตัวแปร (Variables Panel) ให้สร้างชุดสี สำหรับลำดับการเปลี่ยนสีของโลโก้ อย่าลืมใส่สีดั้งเดิมของโลโก้เข้าไปในชุดสีด้วย

โปรเจกต์นี้มีชุดสีทั้งหมด 4 ชุด รวมถึงชุดสีดั้งเดิมของโลโก้ด้วย (color-set-1)

Step 2

จากนั้นสร้างตัวแปรสีหลักของโลโก้ และเชื่อมโยงกับชุดสีดั้งเดิม

ในกรณีนี้สีพื้นฐานอยู่ใน color-set-1

Step 3

คัดลอก CSS ตัวแปรสีจากชุดสีหลักของโลโก้ และเชื่อมกับ fill ที่ใช้ใน SVG ของคุณ

ใช้ var(--ตัวแปรสีหลักของโลโก้ของคุณ) เพื่อเชื่อมโยงค่า

Step 4

สร้างคลาสใหม่สำหรับแต่ละชุดสีที่คุณอยากให้สลับกัน

ใช้ตัวแปรสีหลักของโลโก้ เช่น --logo-base--color-1 แทนการใส่รหัสสีโดยตรง

ไม่ต้องใช้ var() ที่นี่ — แค่เชื่อมตัวแปรกับสีที่ต้องการในแต่ละชุด

<style>
   
.color-set-1{
    --logo-base--color-1:var(--color-set-1--color-1);
    --logo-base--color-2:var(--color-set-1--color-2);
    --logo-base--color-3:var(--color-set-1--color-3);
}
.color-set-2{
    --logo-base--color-1:var(--color-set-2--color-1);
    --logo-base--color-2:var(--color-set-2--color-2);
    --logo-base--color-3:var(--color-set-2--color-3);
}
.color-set-3{
    --logo-base--color-1:var(--color-set-3--color-1);
    --logo-base--color-2:var(--color-set-3--color-2);
    --logo-base--color-3:var(--color-set-3--color-3);
}
.color-set-4{
    --logo-base--color-1:var(--color-set-4--color-1);
    --logo-base--color-2:var(--color-set-4--color-2);
    --logo-base--color-3:var(--color-set-4--color-3);
}
</style>

Step 5

เพิ่มโค้ด CSS นี้เพื่อให้การเปลี่ยนสีนุ่มนวล

เปลี่ยน "color-logo" ให้ตรงกับคลาสที่คุณตั้งไว้ในขั้นตอนที่ 1

.color-logo svg path {
	transition: fill 3s ease-in-out;
}

นี้จะช่วยให้การเปลี่ยนสีของ fill ดูลื่นไหลมากขึ้น

คุณสามารถปรับความเร็วได้โดยเปลี่ยนเลข 3 ตามต้องการ

Step 6

คัดลอกและวาง JavaScript ด้านล่างไว้ก่อนปิดแท็ก </body> ของคุณ

อย่าลืมเปลี่ยน '.color-logo' ให้เป็นคลาสเดียวกันที่ใช้ในขั้นตอนที่ 1

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const containers = document.querySelectorAll('.color-logo');
    const colorClasses = ['color-set-1', 'color-set-2', 'color-set-3', 'color-set-4'];
    let currentSet = 0;

    function updateColors() {
      containers.forEach(container => {
        container.classList.remove(...colorClasses);

        container.classList.add(colorClasses[currentSet]);
      });

      currentSet = (currentSet + 1) % colorClasses.length;

      // Next update after 5 seconds (3s transition + 2s pause)
      setTimeout(pauseBeforeNext, 3000);
    }

    // 2s pause before next color set update
    function pauseBeforeNext() {
      setTimeout(updateColors, 2000);
    }
    pauseBeforeNext();
  });
</script>
เพิ่มชุดสีใหม่ได้โดยอัปเดต const colorClasses = ['color-set-1', 'color-set-2', 'color-set-3', 'color-set-4']; ด้วยชื่อคลาสใหม่ให้ตรงกับที่สร้างไว้ในขั้นตอนที่ 5
ปรับระยะเวลาแอนิเมชันโดยแก้ไข setTimeout(pauseBeforeNext, 3000); และตั้งค่าช่วงหยุดระหว่างรอบการเปลี่ยนสีด้วย setTimeout(updateColors, 2000);