在引导模式中打开放大图像

如何使用jquery/js和而不是数据属性在模式中打开/放大图像

每当用户将图像插入到内容编辑器中时,我都需要它能够被单击以在js模式下展开,因此我不能依赖用户输入他们不知道如何使用的数据属性

我试过:-

<a href=”https://stackoverflow.com/myImage.png“id=”pop“>
<img src=”https://stackoverflow.com/myImage.png“style=”宽度:400px;高度:264px;“>
点击查看大图
&lt/a>

jQuery:-

$(“#pop”)。在(“单击”,函数(){
$(this.modal();
});

我是否需要向jquery添加信息以传递图像源以显示在模式中

谢谢你

如果您使用的是bootstrap 3,则可以尝试此代码:

HTML

<a href=“”id=“pop”>
<img id=“imageresource”src=”http://patyshibuya.com.br/wp-content/uploads/2014/04/04.jpg“style=”宽度:400px;高度:264px;“>
点击查看大图
&lt/a>
<!--创建映像将出现的引导模式-->
<div class=“modal fade”id=“imagemodal”tabindex=“-1”role=“dialog”aria labelledby=“myModalLabel”aria hidden=“true”>
<div class=“模态对话框”>
<div class=“模态内容”>
<div class=“模态标题”>
<按钮类型=“按钮”类=“关闭”数据解除=“模式”&gt&书信电报;span aria hidden=“true”&gt&时代&lt/span&gt&书信电报;span class=“仅限sr”>关闭&lt/span&gt&lt/按钮>
<h4 class=“模态标题”id=“myModalLabel”>图像预览&lt/h4>
&lt/部门>
<div class=“模态体”>
<img src=“”id=“imagepreview”style=“宽度:400px;高度:264px;”;
&lt/部门>
<div class=“模态页脚”>
<button type=“button”class=“btn btn default”数据解除=“模态”>关闭&lt/按钮>
&lt/部门>
&lt/部门>
&lt/部门>
&lt/部门>

JavaScript:

$(“#pop”)。在(“单击”,函数(){
$('#imagepreview').attr('src',$('#imageresource').attr('src'));//在这里,当用户单击放大链接时,将图像指定给模式
$('#imagemodal').modal('show');//imagemodal是分配给引导模式的id属性,然后我使用show函数
});

这是工作小提琴。
希望这有帮助:)

发表评论