Skip to content

Instantly share code, notes, and snippets.

@rajanaresh
Last active August 29, 2015 14:18
Show Gist options
  • Save rajanaresh/51d536ae60fa7abbf6c5 to your computer and use it in GitHub Desktop.
Save rajanaresh/51d536ae60fa7abbf6c5 to your computer and use it in GitHub Desktop.
Tooltip sample JS, CSS, HTML
body{
padding: 50px;
}
#container {
position: fixed;
display: none;
border: 1px red solid;
z-index: 4;
}
li {
background-color: white;
}
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<a href="#test" title="My tooltip text">Sample link</a>
<div><span id="sample" class="noselect"> sample text </span></div>
<div id="container" class="noselect">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>
</div>
$(document).ready(function() {
var c = $('#container');
var s = $('#sample');
var li = c.find('li');
console.log(li);
li.each(function(i, elem) {
$(elem).mouseout(function(e) {
$(elem).css('background-color', 'white');
});
});
li.each(function(i, elem) {
$(elem).mouseover(function(e) {
$(elem).css('background-color', 'blue');
console.log(e.target.innerHTML);
});
});
s.mousedown(function(e) {
c.show();
c.css('top', e.clientY);
c.css('left', e.clientX);
});
$(document).mouseup(function(e) {
c.hide();
});
/*c.mouseover(function(e) {
$(e.target).css('background-color', 'blue');
console.log(e.target.innerHTML);
});*/
});
@rajanaresh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment