Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <div id="parent" style="width: 100px; overflow: hidden;">
    <span id="text">long text that we need to animate<span>
  </div>
</body>
</html>
 
#text {
  position: relative;
  top: 0;
  left: 0;
  display:inline-block; 
  white-space: nowrap;
  animation-name: bounce;
  animation-duration: 5s;
  animation-iteration-count: infinite;
}
@keyframes bounce {
    0% {  transform: translateX(10%)    }
    50%   {  transform: translateX(-100%) }
    100% {  transform: translateX(10%)    }
}
 
let text = document.getElementById("text");
text.style.width = ((text.scrollWidth - text.parentNode.clientWidth) || 0) + "px";
console.log(text.style.width);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers