Created
June 1, 2010 23:18
-
-
Save mkhl/421677 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Source: http://ignorethecode.net/blog/2010/04/20/footnotes/ | |
// Author: Lukas Mathis | |
// this script requires jQuery | |
$(document).ready(function() { | |
Footnotes.setup(); | |
}); | |
var Footnotes = { | |
footnotetimeout: false, | |
setup: function() { | |
var footnotelinks = $("a[rel='footnote']") | |
footnotelinks.unbind('mouseover',Footnotes.footnoteover); | |
footnotelinks.unbind('mouseout',Footnotes.footnoteoout); | |
footnotelinks.bind('mouseover',Footnotes.footnoteover); | |
footnotelinks.bind('mouseout',Footnotes.footnoteoout); | |
}, | |
footnoteover: function() { | |
clearTimeout(Footnotes.footnotetimeout); | |
$('#footnotediv').stop(); | |
$('#footnotediv').remove(); | |
var id = $(this).attr('href').substr(1); | |
var position = $(this).offset(); | |
var div = $(document.createElement('div')); | |
div.attr('id','footnotediv'); | |
div.bind('mouseover',Footnotes.divover); | |
div.bind('mouseout',Footnotes.footnoteoout); | |
var el = document.getElementById(id); | |
div.html($(el).html()); | |
div.css({ | |
position:'absolute', | |
width:'400px', | |
opacity:0.9 | |
}); | |
$(document.body).append(div); | |
var left = position.left; | |
if(left + 420 > $(window).width() + $(window).scrollLeft()) | |
left = $(window).width() - 420 + $(window).scrollLeft(); | |
var top = position.top+20; | |
if(top + div.height() > $(window).height() + $(window).scrollTop()) | |
top = position.top - div.height() - 15; | |
div.css({ | |
left:left, | |
top:top | |
}); | |
}, | |
footnoteoout: function() { | |
Footnotes.footnotetimeout = setTimeout(function() { | |
$('#footnotediv').animate({ | |
opacity: 0 | |
}, 600, function() { | |
$('#footnotediv').remove(); | |
}); | |
},100); | |
}, | |
divover: function() { | |
clearTimeout(Footnotes.footnotetimeout); | |
$('#footnotediv').stop(); | |
$('#footnotediv').css({ | |
opacity: 0.9 | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment