Bootstrap popover, image as content

前端 未结 3 2020
余生分开走
余生分开走 2020-12-08 07:41

I\'m trying to this:

$(\"a[rel=popover]\").popover({
    html:       true,
    trigger:    \'hover\',
    content:    \'

        
相关标签:
3条回答
  • 2020-12-08 07:53

    An alternative to what merv proposed, for simplicity you can embed a lot of the jquery properties to the html and leave the jquery lightweighted e.g

    <a href="#" data-toggle="popover" title="Popover Header" data-html="true" data-content="<img src='http://localhost:15249/img1.jpg' width='200' />">Toggle popover</a>
    

    and call the popover via jquery

    $('["popover"]').popover()
    

    Points to note when using this approach, the data-html should be set to true, else the image is not interpreted as html but as text

    0 讨论(0)
  • 2020-12-08 07:54

    As it currently stands your this is referencing the current scope, whereas you want to be referencing the element which the Popover instance is attached to. This is done simply by wrapping the expression you have for content in a function:

    $('a[rel=popover]').popover({
      html: true,
      trigger: 'hover',
      content: function () {
        return '<img src="'+$(this).data('img') + '" />';
      }
    });
    

    See demo:

    Plunker

    0 讨论(0)
  • 2020-12-08 07:54

    try this

    [html]

    <a href="#"><i class="menu-icon fa fa-picture-o fa-3x" data-rel="popover" title="<strong>Hi, I'm Popover</strong>" data-placement="top" data-content="<img src='https://www.google.co.id/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png' width=50% height=50%>"></i></a>
    

    [javascript]

    $(document).ready(function() {
    $('[data-rel=popover]').popover({
      html: true,
      trigger: "hover"
    });
    

    })

    [check this out] https://jsfiddle.net/j4qptkzr/20/

    0 讨论(0)
提交回复
热议问题