IFrame resizing mess

For testing content that dynamically resizes a lot in an iframe.

by ffMathy

HTML

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

CSS

div {
  background-color: red;
  width: 100px;
  height: 100px;
}

JavaScript

$(function() {
	var count = 0;

  setInterval(function() {
    var $element = $("<div></div>");
    $("body").append($element);

    var randomX = getRandomInt(-2000, 2000);  
    var randomY = getRandomInt(-2000, 2000);
    $element.css("margin-top", randomX + "px");
    $element.css("margin-left", randomY + "px"); 
    
    count++;
    if(count >= 100) {
    	var $elements = $("body > div");
      var indexToRemove = getRandomInt(0, $elements.length);
      $elements.get(indexToRemove).remove();
      
      count--;
    }
  }, 100);
  
  function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive
  }
});