Created
June 19, 2014 09:33
-
-
Save Rycochet/7eff774c2e35f4d8d1ac to your computer and use it in GitHub Desktop.
Bootstrap popover - directly under the line clicked on for multi-line texts
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
/*Popover functionality*/ | |
$(window).on('resize', function(event) { | |
$('.show-text').not(this).popover('hide'); | |
}); | |
$(window).on('click', function(event) { | |
if (!$(event.target).hasClass("show-text")) { | |
$('.show-text').popover('hide'); | |
} | |
}); | |
$('.show-text').popover({ | |
animation: false | |
}); | |
$('.show-text').click(function(e) { | |
//var offset = $(e.target).offset(); | |
//e.pageY = offset.top + $(e.target).height(); | |
$('.popover').position({ | |
my: "center top", | |
at: "center bottom", | |
of: e, | |
collision: "fit", | |
using: function(pos, data) { | |
var diff = data.target.top - $(e.target).offset().top, | |
top = pos.top - diff, | |
height = parseFloat($(e.target).css("line-height")); | |
while (diff > height) { | |
diff -= height; | |
top += height; | |
} | |
$(this).css({ | |
top: top + height + 11, | |
left: pos.left | |
}); | |
} | |
}); | |
$('.popover > .arrow').position({ | |
my: "center", | |
at: "center", | |
of: e, | |
collision: "fit", | |
using: function(pos) { | |
$(this).css("left", pos.left); | |
} | |
}); | |
$('.show-text').not(this).popover('hide'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment