admin管理员组文章数量:1278880
So my Twitter Bootstrap
popovers
seem to be positionally challenged when the triggering element is contained within an element with the style -ms-overflow-y: auto;
(a scrollable element within the window).
When the element is scrolled, the popover does not scroll with it.
I would really like the popover to move with the content within this scrollable element. How can I achieve this?
popover code:
$(this).popover({
animation: false,
html: true,
placement: popover.placement || 'auto bottom',
title: popover.title,
content: popover.validationMessage + popover.content,
trigger: 'manual',
container: '.content-panel'
}).click(function (e) {
$('BUTTON[data-toggle="popover"]').each(function (index, element) { $(this).popover('hide'); });
$(this).popover('show');
$('#' + $(this).attr('data-for')).focus();
});
.content-panel
is the scrollable element.
fiddle me this, Batman
/
Update
I would like the popover to continue floating overtop the other elements. When using position:relative;
on the parent element it contains the popover instead of letting it float over top.
Bad
Good
So my Twitter Bootstrap
popovers
seem to be positionally challenged when the triggering element is contained within an element with the style -ms-overflow-y: auto;
(a scrollable element within the window).
When the element is scrolled, the popover does not scroll with it.
I would really like the popover to move with the content within this scrollable element. How can I achieve this?
popover code:
$(this).popover({
animation: false,
html: true,
placement: popover.placement || 'auto bottom',
title: popover.title,
content: popover.validationMessage + popover.content,
trigger: 'manual',
container: '.content-panel'
}).click(function (e) {
$('BUTTON[data-toggle="popover"]').each(function (index, element) { $(this).popover('hide'); });
$(this).popover('show');
$('#' + $(this).attr('data-for')).focus();
});
.content-panel
is the scrollable element.
fiddle me this, Batman
http://jsfiddle/VUZhL/171/
Update
I would like the popover to continue floating overtop the other elements. When using position:relative;
on the parent element it contains the popover instead of letting it float over top.
Bad
Good
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Mar 24, 2014 at 9:50 Sam AxeSam Axe 33.7k10 gold badges60 silver badges91 bronze badges 4- You should provide a jsfiddle – A. Wolff Commented Mar 24, 2014 at 9:55
- Would love to, but I can't seem to get jsfiddle to show a popover. – Sam Axe Commented Mar 24, 2014 at 10:11
- jsfiddle/KyleMit/VUZhL e.g – A. Wolff Commented Mar 24, 2014 at 10:12
- I don't know why you deleted your answer @A.Wolff. It was exactly what I was looking for! – Sam Axe Commented Mar 24, 2014 at 19:26
2 Answers
Reset to default 5Parent element (offsetParent) of popover need to not be static
, you could postionned it relatively to document:
position: relative;
See jsFiddle
EDIT: for your use case, you could bind onscroll
event of container and use following snippet:
SEE jsFiddle
$(function () {
$('#example').popover();
$('div').on('scroll', function () {
var $container = $(this);
$(this).find('.popover').each(function () {
$(this).css({
top: - $container.scrollTop()
});
});
});
});
For BS 3 and above
you can use container: $(element)
Example:
let elem = $(this)
$(elem).popover({
selector: '[rel=popover]',
trigger: 'hover',
container: $(elem),
placement: 'bottom',
html: true,
content: 'Popover Content'
});
本文标签: javascriptPopover does not get anchored to the triggering elementStack Overflow
版权声明:本文标题:javascript - Popover does not get anchored to the triggering element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741280191a2369963.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论