I've been trying to position a <div>
element where I click.
This is the div that I want to position
<main class="">
<div class="overlay"></div>
@Html.Raw(ViewBag.Breadcrumb)
<div class="split">
<div class="half">
<div class="section-head">
<i class="section-icon fa fa-calendar"></i>
<h2>mon Calendrier</h2>
<small>Dates à retenir</small>
</div>
<div class="calendar-container">
<!-- CALENDAR -->
<div class="action-calendar"></div>
<!-- TOOLTIP -->
<div class="tooltip-wrapper">
<div class = "day-event">
<span class="title"></span>
</div>
</div>
</div>
</div>
</div>
</main>
This is binded to an event on a calendar (if I have a date which has an event associated with it).
What I want to obtain is , as soon as I click on a date I want this <div>
to be placed where the mouse was clicked.
Found this in my search for something that could help me [How do I position a div next to a mouse click using JQuery? but it didn't helped me. The div was changing position but not even close on where I clicked.
This is the code that should do the trick:
var tooltip_HTML = $(".day-event .title").html();
var position = $(".action-calendar a.ui-state-active").parent().offset();
$(".tooltip-wrapper").css({ top: position.top, left: position.left })
THE CSS
.tooltip-wrapper .title{
color:#ffffff;
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
.tooltip-wrapper{
position: absolute;
z-index: 2000;
width: 100%
}
.tooltip-wrapper .day-event {
background: #000000;
position: relative;
width:250px;
color: #FFFFFF;
/*height: 100px;*/
line-height: 20px;
text-align: center;
border-radius: 10px;
opacity: 0.9;
filter: Alpha(opacity=90);
z-index: 10000;
}
.tooltip-wrapper span:after {
content: '';
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -8px;
width: 0;
height: 0;
border-bottom: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
The thing is that it changes the position but not where it suppose.
Thank you.