JSFiddle - React, Tailwind, and code Playground
by djsbellini
HTML
<p>Arcu pulvinar pid nec! Massa pulvinar habitasse aliquet in a montes, proin lectus quis diam ut? Magna proin vel magna, in ridiculus dapibus magna porta hac lectus, nisi placerat tristique, enim sed ut tincidunt porta aliquet, mus odio. Tempor tristique, sit nascetur, odio a scelerisque lorem mid aliquet, phasellus scelerisque, nunc, phasellus nec eu. Nunc tristique nascetur hac, non etiam.</p>
<p>Magna in, cursus, tincidunt a sit a nec porttitor placerat integer rhoncus pid montes, rhoncus porttitor aliquet vel hac! Tempor sit placerat egestas, tristique odio rhoncus vel ut et. Phasellus. Aliquam! Elementum rhoncus sit turpis, mattis pulvinar dolor duis, vut tristique odio tempor, ultrices pulvinar vel elementum dis velit, tincidunt parturient, ut proin! Aenean elit rhoncus in! Scelerisque ridiculus.</p>
<p class="target">text</p>
<div class="blue">
<div class="red">
<div class="green">
<div class="yellow">
<div class="pink">
</div>
<div class="pink">
</div>
<div class="pink">
<p>blah</p>
</div>
</div>
</div>
</div>
</div>
CSS
p.target {
font: 24px bold;
text-align: center;
text-transform: uppercase;
}
p.enter {
background: yellow;
}
p.leave {
background: red;
}
p {
display:block;
background: grey;
margin-bottom: 1em;
}
div {
background: grey;
padding: 10px;
margin: 10px;
}
.blue { background: blue; }
.red { background: red; }
.green { background: green; }
.yellow { background: yellow; }
.pink { background: pink; }
body * { pointer-events: none; }
JavaScript
$.fn.draghover = function(options) {
return this.each(function() {
var collection = $(),
self = $(this);
self.on('dragenter', function(e) {
if (collection.size() === 0) {
self.trigger('draghoverstart');
}
collection = collection.add(e.target);
});
self.on('dragleave drop', function(e) {
// timeout is needed because Firefox 3.6 fires the dragleave event on
// the previous element before firing dragenter on the next one
setTimeout( function() {
collection = collection.not(e.target);
if (collection.size() === 0) {
self.trigger('draghoverend');
}
}, 1);
});
});
};
function setText(text) {
$('p.target')
.text(text)
.removeClass('enter leave')
.addClass(text);
}
$(document).ready(function() {
$(window).draghover().on({
'draghoverstart': function() {
setText('enter');
},
'draghoverend': function() {
setText('leave');
}
});
});