Как использовать popover из Twitter Bootstrap для отображения изображения?
Канонический пример функции Twitter Bootstrap popover - это своего рода подсказка о стероидах с названием.
HTML:
<a href="#" id="blob" class="btn large primary" rel="popover" data-content="And here some amazing content. It very engaging. right?" data-original-title="A title">hover for popover</a>
JS:
<script>
$("#blob").popover({offset: 10});
</script>
Я хотел бы использовать popover для отображения изображения. Это возможно?
Ответы
Ответ 1
Очень просто:)
<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/
Ответ 2
Относительно того, что сказал mattbtay, но несколько изменений. html: true.
Поместите этот script в нижней части страницы, чтобы закрыть тег тела.
<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>
Затем HTML:
<a href="#" rel="drevil">mischief</a>
Ответ 3
Это то, что я использовал.
$('#foo').popover({
placement : 'bottom',
title : 'Title',
content : '<div id="popOverBox"><img src="http://i.telegraph.co.uk/multimedia/archive/01515/alGore_1515233c.jpg" /></div>'
});
и для HTML
<b id="foo" rel="popover">text goes here</b>
Ответ 4
простой с сгенерированными ссылками:)
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/
Ответ 5
Здесь у меня есть пример Bootstrap 3 popover, показывающий изображение с титром над ним, когда мышь нависает над некоторым текстом. Я добавил несколько встроенных стилей, которые вы можете захотеть вынуть или изменить.....
Это также хорошо работает на мобильных устройствах, потому что изображение будет отображаться на первом касании, и ссылка откроется во второй.
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/