JSFiddle - React, Tailwind, and code Playground
HTML
<div id="box"></div>
CSS
#box {
width:150px;
height:150px;
background-color:beige;
border:1px solid black;
cursor: pointer;
}
JavaScript
$(function () {
var $window = $(window);
$('#box').draggable();
$('#box').contextmenu(function (e) {
e.preventDefault();
var boxWidth = $('#box').width();
var boxOffset = $(this).offset();
boxOffset.left += boxWidth + 20;
if (boxOffset.left + boxWidth > $window.width()) {
boxOffset.left -= (boxWidth + 20) * 2;
}
$('<div>').css({
width: "150px",
height: "150px",
'background-color': 'red',
position: 'absolute'
})
.offset(boxOffset)
.appendTo('body');
});
});