I'm trying to achieve this result:
Features:
- Tooltip shows instantly, on click.
- FadeIn and position animation starts at same time, and then, still while animating position, the element fades out.
- Several tooltips can be visible at once (in case two or more buttons are clicked shortly one after another)
- Message content is taken from a dynamic JSON object.
I'm able to duplicate and display the tooltip onclick, but for some reason unable to animate it, or replace it's content.
I don't get how can I select the new duplicated element.
See example error below, or jsFiddle.
html:
<div id="ptsAlert">
<span class="ptsAlert">
message
<div class="ptsAlert-arrow"></div>
</span>
</div>
<table>
<tr>
<td class="btn">01</td>
<td class="btn">02</td>
<td class="btn">03</td>
</tr>
<tr>
<td class="btn">04</td>
<td class="btn">05</td>
<td class="btn">06</td>
</tr>
</table>
css:
h1 {
font-size:50px;
margin:10px;
}
body {
text-align:center;
}
td {
border: 1px solid;
padding: 5px;
cursor: pointer;
}
.ptsAlert {
display:none;
background-color: #EE0000;
color: #FFFFFF;
font-size: 27px;
font-weight: bold;
line-height: 1.7em;
margin: 10px auto;
padding: 0 10px;
position: absolute;
text-align: center;
}
.ptsAlert-arrow{
border-color: #EE0000 transparent transparent;
border-style: solid;
border-width: 8px;
bottom: -15px;
height: 0;
left: 3px;
position: absolute;
width: 0;
}
jQuery:
//Function to show points alerts
$('.btn').click(function(event) {
var points = 10;
$('#ptsAlert').clone(true, true).contents()
.appendTo('body')
.css('top', (event.pageY - 75) + 'px')
.css('left', (event.pageX - 10) + 'px')
.css('display', 'inline-block')
//.hide().fadeIn();
});
The commented line .hide().fadeIn()
produces the following error:
NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMWindow.getComputedStyle]