javascript - Change the popover location dynamically while resizing browser window - Stack Overflow

I am using Twitter Bootstrap popover and I don't know how would be able to change the popover loca

I am using Twitter Bootstrap popover and I don't know how would be able to change the popover location dinamic while resizing browser window. The problem is that when i resize the window, popover stays fixed on position. I want to delay the popover like other html elements.

Code:

$('#popover1').popover({
    html : true,
    content: function() {
        return $("#form").html();
    },
    placement: "top"
});

I am using Twitter Bootstrap popover and I don't know how would be able to change the popover location dinamic while resizing browser window. The problem is that when i resize the window, popover stays fixed on position. I want to delay the popover like other html elements.

Code:

$('#popover1').popover({
    html : true,
    content: function() {
        return $("#form").html();
    },
    placement: "top"
});
Share Improve this question edited Dec 4, 2013 at 18:30 Mike Atlas 8,2414 gold badges47 silver badges63 bronze badges asked Jun 19, 2013 at 21:02 ErikErik 3352 gold badges9 silver badges19 bronze badges 2
  • $(window).on('resize', function() { /* reposition popover here */ }); – BenM Commented Jun 19, 2013 at 21:03
  • Solution : github./twbs/bootstrap/issues/3117 – user Commented May 29, 2014 at 17:54
Add a ment  | 

2 Answers 2

Reset to default 3

This works for me. It calls the show event for all visible popovers:

$(window).off("resize").on("resize", function() {
    $(".popover").each(function() {
        var popover = $(this);
        if (popover.is(":visible")) {
            var ctrl = $(popover.context);
            ctrl.popover('show');
        }
    });
});

Have a look at the following questions and answers:

  • Bootstrap Popover showing at wrong place upon zoom in/out or resizing Browser window
  • jQuery position element based on window resize

You need to use an event handler for the resize event:

$(window).resize(function() {
  // your positioning code here
});

Within this code you must reposition your element.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744744409a4591219.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信