Add Marquee Effect In Shopify Announcement Bar?

Follow below steps:

  • Go to theme -> Edit code
  • Add a new section ‘marquee’
  • Paste the below code
  • Include code into theme.liquid
<style>
  .custom-marquee {
    position: relative;
    width: 100vw;
    max-width: 100%;
    height: 43px;
    overflow-x: hidden;
    background:{{section.settings.colorBackground}};
    color:{{section.settings.colorText}};
  }
  .custom-marquee a {
    color:{{section.settings.colorText}};
  }
  .custom-marquee .track {
      position: absolute;
      bottom: 6px;
      white-space: nowrap;
      will-change: transform;
      animation: marquee 7s linear infinite;
  }
  .custom-marquee .content {
    margin-left: 40px;
  }
  @keyframes marquee {
    from {
      transform: translateX(0);
    }
    to {
      transform: translateX(-20%);
    }
  }
</style>
  <div role="region" {{ block.shopify_attributes }}>
    {%- if section.settings.text != blank -%}
      {%- if section.settings.link != blank -%}
        <a href="{{ section.settings.link }}">
      {%- endif -%}
          <div>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            <span>{{ section.settings.text | escape }}</span>
            {%- if section.settings.link != blank -%}
              {% render 'icon-arrow' %}
            {%- endif -%}
          </div>
          {%- if section.settings.link != blank -%}
        </a>
      {%- endif -%}
    {%- endif -%}
  </div>
<script>
var marquees = document.getElementsByClassName("marquee-text");
for (let i = 0; i < marquees.length; i++) {
   // console.log(marquees.item(i));
  let str = marquees.item(i).innerHTML;
  let improvedText = str.replaceAll("|", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
  console.log(improvedText)
  marquees.item(i).innerHTML = improvedText
}
</script>
{% schema %}
{
  "name": "Marquee Announcement",
  "settings": [
    {
      "type": "text",
      "id": "text",
      "default": "Welcome to our store",
      "label": "Add text to display"
    },
    {
      "type": "color",
      "id": "colorBackground",
      "label": "Background color",
      "default": "#000"
    },
    {
      "type": "color",
      "id": "colorText",
      "label": "Text color",
      "default": "#fff"
    },
    {
      "type": "url",
      "id": "link",
      "label": "Link"
    }
  ]
}
{% endschema %}

https://youtu.be/0ygeQz7OLCc