2

I would like to detect animation-unsupported browsers and like to disable animation in them and to show only plain text there. Is there any way I can do this ? I'm a Newbie to JavaScript and CSS also :)

Also , if you could, could you please tell me how to correct the problem that the text output is always together,means that no spacing between words, How should I correct it out ?

var data = [{
    "text": "Genius is one percent inspiration and ninety-nine percent perspiration.",
    "author": "Thomas Edison"
  },
  {
    "text": "You can observe a lot just by watching.",
    "author": "None"
  }
];

function unsecure() {
  var index = Math.floor(Math.random() * data.length);
  var quote = data[index].text;
  var author = data[index].author;
  if (!author) {
    author = "Anonymous"
  }
  document.getElementById("h1").innerHTML = quote;
  document.getElementById("h2").innerHTML = "~ " + author;
  var text = document.getElementsByClassName("th");

  function myFunc(text) {
    var newDom = '';
    var animationDelay = 6;

    for (let i = 0; i < text.innerText.length; i++) {
      newDom += '<span class="char">' + (text.innerText[i] == ' ' ? ' ' : text.innerText[i]) + '</span>';
    }

    text.innerHTML = newDom;
    var length = text.children.length;

    for (let i = 0; i < length; i++) {
      text.children[i].style['animation-delay'] = animationDelay * i + 'ms';
    }
  }

  myFunc(text[0]); // call functions with your items.
  myFunc(text[1]);
}
.char {
  font-size: 40px;
  height: 40px;
  animation: an 1s ease-out 1 both;
  display: inline-block;
}

@supports (display:grid) {
  @keyframes an {
    from {
      opacity: 0;
      transform: perspective(500px) translate3d(-35px, -40px, -150px) rotate3d(1, -1, 0, 35deg);
    }
    to {
      opacity: 1;
      transform: perspective(500px) translate3d(0, 0, 0);
    }
  }
}

.btn {
  outline: none;
  background: #fcfcfc;
  background-image: -webkit-linear-gradient(top, #fcfcfc, #ed51ce);
  background-image: -moz-linear-gradient(top, #fcfcfc, #ed51ce);
  background-image: -ms-linear-gradient(top, #fcfcfc, #ed51ce);
  background-image: -o-linear-gradient(top, #fcfcfc, #ed51ce);
  background-image: linear-gradient(to bottom, #fcfcfc, #ed51ce);
  -webkit-border-radius: 28;
  -moz-border-radius: 28;
  border-radius: 28px;
  -webkit-box-shadow: 0px 1px 13px #666666;
  -moz-box-shadow: 0px 1px 13px #666666;
  box-shadow: 0px 1px 13px #666666;
  font-family: Arial;
  color: #050505;
  font-size: 20px;
  padding: 10px 20px 10px 20px;
  border: solid #ff0000 2px;
  text-decoration: none;
}

body {
  height: auto;
  -webkit-background-size: auto;
  -moz-background-size: auto;
  -o-background-size: auto;
  background-size: auto;
}
<!DOCTYPE html>

<head>
  <title>Test</title>
</head>

<body onload=unsecure()>
  <center>
    <font face="Sansation-Regular">
      <h1><u> Quote For You </u></h1>
      <h1 id="h1" class="th"></h1>
      <h2 id="h2" class="th"></h2>
      <br></font>
    <button onclick=unsecure() class="btn">Another One</button>
  </center>
</body>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
SimpleGuy_
  • 443
  • 5
  • 12
  • Is there any way of finding out incompatibility using ```result = CSS.supports(what to write here);``` way ? – SimpleGuy_ Sep 24 '21 at 07:43
  • if the browser doesnt support it, isnt the animation "disabled" automatically since there is no way to support it? – The Fool Sep 24 '21 at 07:46
  • @TheFool Yeah,But my text also disappears with it – SimpleGuy_ Sep 24 '21 at 08:06
  • 1
    For the spaces, check the `display: inline-block;` for the char it might have something to do with it,because i noticed the spaces are there in the inspector but their `width` is 0px, which is why they're not showing. – Hadi Hoteit Sep 24 '21 at 08:17

0 Answers0