I'm having a hard time converterting the following JS to JQuery.
My project have a #HoverMe
div where I hover it to display the content inside #hidden
div.
I've a well working JS script from ( this question, by anied). I tried to re-write document.getElementById("HoverMe");
to $("#HoverMe").hover(function() {
etc, but I can't go any further as my understanding in jQuery is zero.
This is how my divs look like
------------ --------- _
| #HoverMe | | #hidden |S| //hover #HoverMe to display #hidden
------------ | --------|R|
| car.name|O|
|---------|L|
| car.name|L|
---------|B|
| car.name|A|
|---------|R|
| car.name| |
---------|_|
<div>
<div id="HoverMe" style="width: 100px; background: green">
Car
</div>
<div id="hidden" style="overflow:auto; height:100px; position: absolute; background-color: red; display: none">
@foreach (var car in Model.Car) { @* Where the #hidden list get its content *@
<div>@car.Name</div>
}
</div>
</div>
How to convert following JS to JQuery?
var hoverEle = document.getElementById("HoverMe");
var popupEle = document.getElementById("hidden");
var timeoutId;
function showPopup() {
var hoverRect = hoverEle.getBoundingClientRect(); // get the position of the hover element
popupEle.style.left = (hoverRect.right + 16) + "px";
popupEle.style.top = hoverRect.top + "px";
popupEle.style.display = "block";
}
function hidePopup() {
popupEle.style.display = "none";
}
hoverEle.addEventListener('mouseover', function () {
showPopup();
}, false);
hoverEle.addEventListener('mouseout', function () {
timeoutId = window.setTimeout(function () {
hidePopup();
}, 1500);
}, false);
popupEle.addEventListener('mouseover', function () {
if (timeoutId) {
window.clearTimeout(timeoutId);
}
}, false);
popupEle.addEventListener('mouseout', function () {
timeoutId = window.setTimeout(function () {
hidePopup();
}, 1500);
}, false);
</script>