JSFiddle - React, Tailwind, and code Playground

HTML

<div class="test"></div>

CSS

div{
    width:100px;
    height:100px;
    background:#eee;
}

JavaScript

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