最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论