What could be causing the mysterious disappearance of points on my SVG post-animation?

I am experiencing a small issue with my SVG animation. Once the animation is completed, blank points appear on the SVG text. I have included my code pen with the complete code for you to see it firsthand. Interestingly, this problem only occurs in Chrome, Opera, and Edge browsers, while Firefox works fine. After checking the "can i use" website, it seems that my code is correct. Can someone please explain why these blank points are appearing after the animation?

const logo = document.querySelectorAll('#logo path');
for (i = 8; i < logo.length; i++) {
  console.log(`outline:  ${logo[i].getTotalLength()}`);
  console.log(`mask:  ${logo[i-8].getTotalLength()}`);
}

// Function adding appropriate commands to each path

const svgText = () => {
  const pathLengths = ['580', '470', '505', '235', '645', '614', '473', '558'];
  const delayArray = ['0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4'];
  const delayArray2 = [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000];
  for (i = 8; i < logo.length; i++) {
    logo[i].style.strokeDasharray = pathLengths[i - 8] + 'px';
    logo[i].style.strokeDashoffset = pathLengths[i - 8] + 'px';
    logo[i].style.animationFillMode = 'forwards';
    debugger;
    logo[i].animate([{
      strokeDashoffset: '0'
    }], {
      duration: 3500,
      delay: delayArray2[i - 8],
      fill: 'forwards'
    })
    logo[i - 8].animate([{
      fill: 'white'
    }], {
      duration: 2000,
      delay: 5000,
      fill: 'forwards'
    })
  }
}

svgText();
body,
html {
  padding: 0px;
  margin: 0px;
  width: 100%;
  height: 100%;
}

.container {
  background-color: black;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.as-console-wrapper {
  max-height: 50px !important;
}
<html lang="pl">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="style.css">
  <script src="https://kit.fontawesome.com/6c45422137.js" crossorigin="anonymous"></script>
  <title>SVGG</title>
</head>

<body>
  <div class="container">
    <div class="svg">
      <svg id="logo" width="400" height="118" viewBox="0 0 672 118" fill="none" xmlns="http://www.w3.org/2000/svg">
                <mask id="path-1-outside-1" maskUnits="userSpaceOnUse" x="0.908325" y="0.335995" width="671" height="117" fill="black">
                <rect fill="white" x="0.908325" y="0.335995" width="671" height="117"/>
                <path d="M39.1563 8.632C50.1003 8.632 59.5563 10.696 67.5243 14.824C75.5883 18.856 81.7323 24.664 85.9563 32.248C90.2763 39.832 92.4363 48.76 92.4363 59.032C92.4363 69.304 90.2763 78.232 85.9563 85.816C81.7323 93.304 75.5883 99.064 67.5243 103.096C59.5563 107.032 50.1003 109 39.1563 109H7...
    </div>

  </div>
  <script type="text/javascript" src="script.js"></script>
</body>

</html>

Answer №1

Within your SVG code, the <path> elements are currently set to draw a stroke with a default linecap of butt, causing them to round at the start and end with a small crop.

To prevent this cropping effect and make the ends square instead, you can specify the stroke-linecap property for all <path> elements as square.

path {
  stroke-linecap: square;
}

In the provided JavaScript snippet, there is a function svgText() that adds commands to each path element within the SVG. It sets different properties such as strokeDasharray, strokeDashoffset, and initiates animations.

The CSS styles in the code adjust the layout of the HTML document, including setting the background color, dimensions, display properties, etc., while also targeting the path elements to ensure a consistent styling.

The HTML document contains the SVG markup along with links to external CSS and JavaScript files, making use of Font Awesome icons and referencing specific classes and IDs within the SVG structure.

Answer №2

Review the following corrections. There are some improvements to be made, especially for the N section:

const logo = document.querySelectorAll('#logo path');
for (i = 8; i < logo.length; i++) {
  console.log(`outline:  ${logo[i].getTotalLength()}`);
  console.log(`mask:  ${logo[i-8].getTotalLength()}`);
}

// function adding appropriate commands to each path

const svgText = () => {
  const pathLengths = ['580', '470', '505', '235', '645', '614', '473', '558'];
  const delayArray = ['0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4'];
  const delayArray2 = [500, 1000, 1500, 2000, 2500, 3000, 3500, 4000];
  for (i = 8; i < logo.length; i++) {
    logo[i].style.strokeDasharray = pathLengths[i - 8] + 'px';
    logo[i].style.strokeDashoffset = pathLengths[i - 8] + 'px';
    logo[i].style.animationFillMode = 'forwards';
    debugger;
    logo[i].animate([{
      strokeDashoffset: '0'
    }], {
      duration: 3500,
      delay: delayArray2[i - 8],
      fill: 'forwards'
    })
    logo[i - 8].animate([{
      fill: 'white'
    }], {
      duration: 2000,
      delay: 5000,
      fill: 'forwards'
    })
  }
}

svgText();
body,
html {
  padding: 0px;
  margin: 0px;
  width: 100%;
  height: 100%;
}

.container {
  background-color: black;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.as-console-wrapper {
  max-height: 50px !important;
}
<html lang="pl">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="style.css">
  <script src="https://kit.fontawesome.com/6c45422137.js" crossorigin="anonymous"></script>
  <title>SVGG</title>
</head>

<body>
  <div class="container">
    <div class="svg">
      <svg id="logo" width="400" height="118" viewBox="0 0 672 118" fill="none" xmlns="http://www.w3.org/2000/svg">
                <mask id="path-1-outside-1" maskUnits="userSpaceOnUse" x="0.908325" y="0.335995" width="671" height="117" fill="black">
                <rect fill="white" x="0.908325" y="0.335995" width="671" height="117"/>
                <path d="M39.1563 8.632C50.1003 8.632 59.5563 10.696 67.5243 14.824C75.5883 18.856 81.7323 24.664 85.9563 32.248C90.2763 39... etc
                </svg>
    </div>

  </div>
  <script type="text/javascript" src="script.js"></script>
</body>

</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering challenges with synchronous calls in AngularJS

Two service calls need to be executed synchronously in a specific order, using promises. However, the execution is not happening as intended. Controller: vm.nominationSVC.zipping(vm.fileSelected, vm.selectedCategoryId). then(function (respons ...

Issues encountered when implementing server-sent events in a project built with Node.js and React

I've been working on implementing server-sent-events into my Node.js and React application. After doing some research and following tutorials online, I found this particular site to be very helpful and straightforward. The main objective is to have a ...

The execution of the Ajax success call is failing to take place

Looking at my recent AJAX call, I realized there might be an issue with how I'm sending the parameters. $.ajax({ type: "POST", url: "Default.aspx/GeneratePdfs", data: '{frequency: "' + $('#ddlReportFrequenc ...

What causes my child element to be positioned with respect to the body even though its parent is set to relative positioning?

Here is the HTML code I am working with: <html> <head></head> <body> <div id="board"> <div class="person"></div> </div> </body> </html> And here is the ...

I'm experiencing some challenges with setting up my sequelize relationships

After tirelessly searching for a solution to my problem and coming up empty-handed, I decided to reach out here. Every Google search result seems unhelpful and every link I click on is disappointingly pink. Hello everyone! I'm facing difficulties est ...

What is the best way to retrieve the result of a JavaScript function in an HTML form?

I'm currently developing a JavaScript app that involves selecting a random question from an array and combining it with a random object from another array. Here's a glimpse of how my app is structured: Array.prototype.random = function (length) ...

I'm looking to mirror images within the Bootstrap framework - any suggestions on how to achieve this using jQuery

When hovering over the image, it should flip to reveal text or a link: <div class="clearfix visible-xs"></div> <div class="col-md-3 col-sm-3 col-xs-6"> <div class="speaker-item animated hiding" data-animation="fade ...

Discover the steps to implement a live user list in a chat application with the help of angular.js, socket.io, and node

Currently, I am in the process of developing a chat application with AngularJS and Socket.io. The current status of my project allows users to send and receive messages from different individuals. To gain access to the chatbox, users need to input their na ...

What is the best way to switch content between tabs using ajax and php?

I have organized my content into two tabs and I am switching between the tabs using JavaScript. <div class='tab-container'> <div class='tab-1'> <?php $sql="SELECT * FROM posts WHERE status='tab1'"; echo "<d ...

CSS declarations that have not been acknowledged or acknowledged

While working on a client's stylesheet today, I came across the following code: p { -webkit-hyphens: auto; -webkit-hyphenate-character: "\2010"; -webkit-hyphenate-limit-after: 1; -webkit-hyphenate-limit-before: 3; -moz-hyphens: manual; orphans: ...

What is the process for converting CSS to SASS when using arithmetics in selectors?

Is there a more efficient way to convert the following CSS code into SASS? div#block-views-news-block, div#block-views-news-block-1, div#block-views-news-block-3, div#block-views-news-block-4 { margin: 0; padding: 0; } I attempted the following: div ...

Is there a way to deactivate the Edge mini menu while selecting text in a React application?

I have recently been working on a React web application and managed to create a specialized text selection menu. However, I am facing a challenge in programmatically disabling the default text selection mini menu in React. The image attached illustrates bo ...

What happens when Google Polymer platform is used without defining _polyfilled?

My attempt at creating a simple example using Google Polymer's platform.js is running into an error message that says: Uncaught TypeError: Cannot read property '_polyfilled' of undefined This is what I'm attempting to achieve: <cur ...

What is the best way to create a moving line using EaselJS and TweenJS?

My objective is to animate a line from point A to point B using the Tween function. I am utilizing the EaselJS drawing library and TweenJS for animation. Can I achieve this by using the moveTo function to animate a straight line from point A to point B? ...

Elements appearing outside their designated container

I'm struggling with my boxes and their content. Each box has different amounts of content, and I can't seem to get them to resize automatically to fit the content. The overflow:hidden; property hasn't helped either. Any suggestions? Thank y ...

What is the best way to apply the !important property in jQuery for CSS styling?

When setting the CSS property "padding-top" to a value stored in a variable (currentHeight), such as: jQuery("#page-container").css("padding-top", currentHeight); It functions correctly and produces: <div id="page-container" style="padding-top: 115px;" ...

When using jQuery AJAX, the script is returning blank values

Facing a frustrating issue here. I'm sending an AJAX request to a PHP file, but when I check Chrome Network Tools, it doesn't return any JSON data. However, when I try posting the same data using POSTMAN in Chrome, it returns correctly. Also, if ...

Display user input within a modal dialogue box

I have a subscription form that requires users to enter their name and email address. After clicking on "Compete Now," a pop-up appears asking for workshop information and postal code. The form is functioning correctly as intended. However, I want the em ...

Leveraging route configuration's scope in HTML

As a beginner in AngularJs, I am currently exploring the creation of a single page application. However, I am encountering difficulties in converting my initial code into more professional and efficient code. During this conversion process, I have separate ...

Managing User-Triggered Requests in Ajax and JavaScript

Currently experimenting with some Ajax code, I have created a scenario to illustrate my issue. I am reaching out to experts for a possible solution, thank you. Scenario: There is an HTML button as follows: <p onclick="ajax_call();">Click</p>. ...