Advertisement
Guest User

Untitled

a guest
Jul 4th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.37 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <title>snote example</title>
  4. <meta charset="utf-8">
  5.  
  6. <!-- Placed in the public domain by Roger Hågensen. -->
  7. <style>
  8. .snote
  9. {
  10.     width: 1em;
  11.     height: 1em;
  12.     background-image: url('http://icons.iconarchive.com/icons/visualpharm/must-have/256/Information-icon.png');
  13.     background-size: auto 1em;
  14.     background-repeat: no-repeat;
  15.     display: none;
  16.     cursor: help
  17. }
  18.  
  19. .snote_tip
  20. {
  21.     display: block;
  22.     visibility: hidden;
  23.     position: absolute;
  24.     width: 16em;
  25.     height: 3em;
  26.     padding: 0.5em;
  27.     overflow: auto;
  28.     background: #cccccc;
  29.     color: #000000;
  30.     border: 0.15em solid #000000;
  31.     border-radius: 0.25em;  
  32.     box-shadow: 0.25em 0.25em 0.25em #7f7f7f;
  33. }
  34.  
  35. .snote_tip:hover
  36. {
  37.     cursor: default;
  38. }
  39. </style>
  40.  
  41. <script>
  42.     //call this function once the page has loaded
  43.     window.addEventListener('load', snote_init, false);
  44.  
  45.     //this function will add a span with snote_tip class where a span with the snote class is used, this reduces the html needed and makes writing notes so much simpler/cleaner.
  46.     function snote_init()
  47.     {
  48.         var snote_elements = document.getElementsByClassName('snote');
  49.         for (var i = 0; i < snote_elements.length; i += 1)
  50.         {
  51.             (function(i)
  52.             {
  53.                 var snote_element = snote_elements[i];
  54.  
  55.                 snote_element.innerHTML = '<span class="snote_tip" id="snote_' + i + '">' + snote_element.innerHTML + '</span>';
  56.                 snote_element.style.display = 'inline-block';
  57.                 snote_element.addEventListener ("mouseup", function () {snote_show(i)}, false);
  58.             })(i);
  59.         }
  60.     }
  61.  
  62.     function snote_show(arg)
  63.     {
  64.         var snote_tip = document.getElementById('snote_' + arg);
  65.         var rect = snote_tip.getBoundingClientRect();
  66.  
  67.         snote_tip.style.top = 'auto';
  68.         snote_tip.style.left = 'auto';
  69.         snote_tip.style.marginLeft = '-' + (rect.width / 2) + 'px';
  70.         snote_tip.style.marginTop = '-' + (rect.height / 2) + 'px';
  71.         var rect = snote_tip.getBoundingClientRect();
  72.         x1 = rect.left;
  73.         y1 = rect.top;
  74.         x2 = window.innerWidth - rect.right
  75.         y2 = window.innerHeight - rect.bottom
  76.         if (x1 < 0)
  77.         {
  78.             snote_tip.style.left = '0px';
  79.             snote_tip.style.marginLeft = '0px';
  80.         }
  81.         if (y1 < 0)
  82.         {
  83.             snote_tip.style.top = '0px';
  84.             snote_tip.style.marginTop = '0px';
  85.         }
  86.         if (x2 < 0)
  87.         {
  88.             snote_tip.style.left = (window.innerWidth-rect.width) + 'px';
  89.             snote_tip.style.marginLeft = '0px';
  90.         }
  91.         if (y2 < 0)
  92.         {
  93.             snote_tip.style.left = (window.innerHeight-rect.height) + 'px';
  94.             snote_tip.style.marginLeft = '0px';
  95.         }
  96.  
  97.         if (snote_tip.style.visibility == 'visible')
  98.         {
  99.             snote_tip.style.visibility = 'hidden';
  100.         }
  101.         else
  102.         {
  103.             snote_tip.style.visibility = 'visible';
  104.         }
  105.     };
  106. </script>
  107.  
  108. <body>
  109.  
  110. <p>But the thing is this: I really, REALLY like annotations. I'm talking about the little numbers that pop up in a post <span class="snote">Like this one, for example.<br><br>And it is really long, but that is not really a problem.<br><br>This text could easily just go on and on.</span>. I ran into them on the <a href="http://what-if.xkcd.com/">XKCD What-If blog</a>.  They're great for expanding on a side-thought without cluttering up the main body of the article. They're handy when writing faux-technical articles that require lots of footnotes to save me from Death By Nitpick. They're great for jokes <span class="snote">Since you can hide the <a href="http://en.wikipedia.org/wiki/Punch_line">punchline</a>.</span>. </p>
  111.  
  112. </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement