如何使用Twitter Bootstrap中的popover来显示图像?

Sco*_*son 50 javascript popover twitter-bootstrap

Twitter Bootstrap的popover功能的典型示例是带有标题的类固醇的工具提示.

HTML:

<a href="#" id="blob" class="btn large primary" rel="popover" data-content="And here's some amazing content. It's very engaging. right?" data-original-title="A title">hover for popover</a>
Run Code Online (Sandbox Code Playgroud)

JS:

<script>
$("#blob").popover({offset: 10});
</script>
Run Code Online (Sandbox Code Playgroud)

我想使用popover来显示图像.这可能吗?

Ter*_*rry 84

非常简单 :)

<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 });
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/weuWk/

  • 要使html正确呈现,需要`html:true` :( (15认同)

小智 14

类似于mattbtay所说的,但有一些变化.需要html:true.
将此脚本放在页面底部朝向贴身标签.

<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>
Run Code Online (Sandbox Code Playgroud)


然后HTML是:

<a href="#" rel="drevil">mischief</a>
Run Code Online (Sandbox Code Playgroud)


Tit*_*100 7

简单的生成链接:) html:

<span class='preview' data-image-url="imageUrl.png" data-container="body" data-toggle="popover" data-placement="top" >preview</span>
Run Code Online (Sandbox Code Playgroud)

JS:

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

http://jsfiddle.net/A4zHC/


mat*_*tay 6

这是我用的.

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

并为HTML

<b id="foo" rel="popover">text goes here</b>
Run Code Online (Sandbox Code Playgroud)