How do I use popover from Twitter Bootstrap to display an image?

后端 未结 5 1823
失恋的感觉
失恋的感觉 2020-12-22 17:45

The canonical example for Twitter Bootstrap\'s popover feature is sort of a tooltip on steroids with a title.

HTML:



        
相关标签:
5条回答
  • 2020-12-22 18:03

    This is what I used.

    $('#foo').popover({
        placement : 'bottom',
        title : 'Title',
        content : '<div id="popOverBox"><img src="http://i.telegraph.co.uk/multimedia/archive/01515/alGore_1515233c.jpg" /></div>'
    });
    

    and for the HTML

    <b id="foo" rel="popover">text goes here</b>
    
    0 讨论(0)
  • 2020-12-22 18:06

    Sort of similar to what mattbtay said, but a few changes. needed html:true.
    Put this script on bottom of the page towards close body tag.

    <script type="text/javascript">
     $(document).ready(function() {
      $("[rel=drevil]").popover({
          placement : 'bottom', //placement of the popover. also can use top, bottom, left or right
          title : '<div style="text-align:center; color:red; text-decoration:underline; font-size:14px;"> Muah ha ha</div>', //this is the top title bar of the popover. add some basic css
          html: 'true', //needed to show html of course
          content : '<div id="popOverBox"><img src="http://www.hd-report.com/wp-content/uploads/2008/08/mr-evil.jpg" width="251" height="201" /></div>' //this is the content of the html box. add the image here or anything you want really.
    });
    });
    </script>
    


    Then HTML is:

    <a href="#" rel="drevil">mischief</a>
    
    0 讨论(0)
  • 2020-12-22 18:12

    simple with generated links :) html:

    <span class='preview' data-image-url="imageUrl.png" data-container="body" data-toggle="popover" data-placement="top" >preview</span>
    

    js:

    $('.preview').popover({
        'trigger':'hover',
        'html':true,
        'content':function(){
            return "<img src='"+$(this).data('imageUrl')+"'>";
        }
    });
    

    http://jsfiddle.net/A4zHC/

    0 讨论(0)
  • 2020-12-22 18:13

    Here I have an example of Bootstrap 3 popover showing an image with the tittle above it when the mouse hovers over some text. I've put in some inline styling that you may want to take out or change.....

    This also works pretty well on mobile devices because the image will popup on the first tap and the link will open on the second. html:

    <h5><a href="#" title="Solid Tiles Template" target="_blank" data-image-url="http://s29.postimg.org/t5pik8lyf/tiles1_preview.jpg" class="preview" rel="popover" style="color: green; font-style: normal; font-weight: bolder; font-size: 16px;">Template Preview 1 <i class="fa fa-external-link"></i></a></h5>
    
    <h5><a href="#" title="Clear Tiles Template" target="_blank" data-image-url="http://s9.postimg.org/rdonet7jj/tiles2_2_preview.jpg" class="preview" rel="popover" style="color: red; font-style: normal; font-weight: bolder; font-size: 16px;">Template Preview 2 <i class="fa fa-external-link"></i></a></h5>
    
    <h5><a href="#" title="Clear Tiles Template" target="_blank" data-image-url="http://s27.postimg.org/8scrcdu9v/tiles3_3_preview.jpg" class="preview" rel="popover" style="color: blue; font-style: normal; font-weight: bolder; font-size: 16px;">Template Preview 3 <i class="fa fa-external-link"></i></a></h5>
    

    js:

    $('.preview').popover({
        'trigger':'hover',
        'html':true,
        'content':function(){
            return "<img src='"+$(this).data('imageUrl')+"'>";
        }
    });
    

    https://jsfiddle.net/pepsimax_uk/myk38781/3/

    0 讨论(0)
  • 2020-12-22 18:24

    Very simple :)

    <a href="#" id="blob" class="btn large primary" rel="popover">hover for popover</a>
    
    var img = '<img src="https://si0.twimg.com/a/1339639284/images/three_circles/twitter-bird-white-on-blue.png" />';
    
    $("#blob").popover({ title: 'Look! A bird!', content: img, html:true });
    

    http://jsfiddle.net/weuWk/

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