JSFiddle - React, Tailwind, and code Playground

by ingomc

HTML

<script src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="container">
  This Container is moved by JS via translate3d  
</div>

CSS

:root {
  --move-x: 1px;
}

.container {
  transform:translate3d(var(--move-x),0,0);
  transition:1s transform ease-in-out;
}

JavaScript

var body = document.querySelector('body');

/* Helper function for getting a random nummber */
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}

/* Change css variable via vanilla js
	I have set an interval to show how JS manipulates the CSS
*/
setInterval(function(){
	body.style.setProperty("--move-x", `${getRandomInt(200)}px`);
},2000)