JSFiddle - React, Tailwind, and code Playground

by jruddell

HTML

<div class="center"> asdf </div>

JavaScript

jQuery.fn.center = function () {
    this.css("position","absolute");
    var top = ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px",
        left = ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px";
    this.animate({top: top, left: left});
    return this;
}
    
    $('div.center').center();