Last active
August 29, 2015 14:08
-
-
Save kshoufer/f27655460e19f7347548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>Tooltip Examples</title> | |
<link rel="stylesheet" type="text/css" href="tooltip.css" /> | |
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<script type="text/javascript" src="tooltip.js"></script> | |
</head> | |
<body> | |
<div class="page"> | |
<header> | |
<a class="logo tooltip" href="#" data-tip-type="text" data-tip-source="This is tooltip text -- 1"></a> | |
</header> | |
<article> | |
<h1>Heading</h1> | |
<aside> | |
<h2>Aside Heading</h2> | |
<p>Lorem ipsum dolor sit amet consectetur <a href="#" id="123" data-tip-type="html" data-tip-source="tooltip-sidebar" class="tooltip">HTML-based tooltip</a> adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p> | |
</aside> | |
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco <a href="#" data-tip-type="text" data-tip-source="This is tooltip text -- 2" class="tooltip">text-based tooltip</a> laboris nisi ut aliquip consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> | |
<div class="clear-all"></div> | |
</article> | |
<footer>Your company name.</footer> | |
<div id="tooltip-container">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, corporis, adipisci. Ducimus corporis neque nam vitae, at totam numquam cumque! Adipisci aliquam quos nam ipsa, laboriosam vel soluta assumenda earum!</div> | |
<div class="tooltip-html-source"> | |
<div id="tooltip-sidebar"> | |
<img src="http://placehold.it/60x60/1B0DBF/ffffff&text=img" style="float:left; padding-right:10px;";/>This is a tip that has <stong><em style="color: #ffe19a;">HTML - formatted</em></strong> content, including an image. | |
<div class="clear-all"></div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Style */ | |
body { | |
font: 12px Arial; | |
margin: 0px; | |
padding: 0px 20px; | |
background-color: #03658b; | |
} | |
h1 { | |
margin: 0 0 1em 0; | |
color: #03658a; | |
font-size: 1.7em; | |
font-weight: normal; | |
} | |
h2 { | |
margin: 0 0 .5em 0; | |
color: #03658a; | |
font-size: 1.3em; | |
} | |
p { | |
margin: 0 0 1em 0; | |
line-height: 1.5em; | |
} | |
a { | |
color: #007CBF; | |
text-decoration: none; | |
background-color: #FAFAAB; | |
border: 1px solid #999; | |
padding:2px; | |
} | |
aside p { | |
color: #777; | |
} | |
footer { | |
font-size: .9em; | |
} | |
/* Layout */ | |
.page { | |
max-width: 600px; | |
width: 600px; | |
margin: 0px auto; | |
padding: 0px; | |
} | |
header { | |
position: relative; | |
height: 28px; | |
margin: 0px; | |
padding-top: 60px; | |
background: url(http://placehold.it/980x115/2E985B/ffffff&text=Header) no-repeat 50% 0px; | |
} | |
header a.logo { | |
width: 120px; | |
height: 50px; | |
position: absolute; | |
top: 15px; | |
left: 15px; | |
background: url(http://placehold.it/120x50/BE620E/ffffff&text=Logo) no-repeat 0px 0px; | |
display: block; | |
} | |
nav { | |
background-color: rgba(0,0,0,.4); | |
} | |
article { | |
margin: 0px; | |
padding: 25px; | |
background-color: #fff; | |
} | |
aside { | |
width: 200px; | |
float: right; | |
margin: 0px 0px 10px 40px; | |
padding: 0px 0px 0px 20px; | |
border-left: 2px solid #ccc; | |
} | |
aside p { | |
margin: 0px; | |
} | |
footer { | |
border-top: 1px solid #ddd; | |
margin: 0px; | |
padding: 10px 25px 10px 10px; | |
color: rgba(255,255,255,.4); | |
} | |
.clear { | |
clear: both; | |
line-height: 1px; | |
} | |
/* Tooltip */ | |
#tooltip-container { | |
color:#fff; | |
position: absolute; | |
padding:20px; | |
max-width: 200px; | |
background-color: rgba(175, 39, 39, .85); | |
webkit-border-radius:12px; | |
mozilla-border-radius:12px; | |
border-radius:12px; | |
display: none; | |
} | |
.tooltip-html-source { | |
display: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$('.tooltip').mouseover(function(e) { | |
if ($(this).attr('data-tip-type') == 'text') { | |
$('#tooltip-container').html($(this).attr('data-tip-source')); | |
} | |
if ($(this).attr('data-tip-type') == 'html') { | |
var elementToGet = '#' + ($(this).attr('data-tip-source')); | |
var newHTML = $(elementToGet).html(); | |
$('#tooltip-container').html(newHTML); | |
} | |
$('#tooltip-container').css({'display':'block', 'opacity':0}).animate({opacity:1}, 250); | |
}).mousemove(function(e) { | |
var toolTipWidth = $('#tooltip-container').outerWidth(); | |
var toolTipHeight = $('#tooltip-container').outerHeight(); | |
var pageWidth = $('body').width(); | |
if (e.pageX > pageWidth/2) { | |
$('#tooltip-container').css('left', (e.pageX-toolTipWidth+20)+'px'); | |
} else { | |
$('#tooltip-container').css('left', (e.pageX-20) + 'px'); | |
} | |
if( e.pageY > 100) { | |
$('#tooltip-container').css('top', (e.pageY-(toolTipHeight+20)) + 'px'); | |
} else { | |
$('#tooltip-container').css('top', (e.pageY+20) + 'px'); | |
} | |
}).mouseout(function(e) { | |
$('#tooltip-container').animate({opacity:0}, 250, function(){ | |
$('#tooltip-container').css('display', 'none').html(''); | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment