bootstrap+jquery 点击显示大图功能

这里用的是bootstrap的模态框

一、页面部分

①模态框部分:

<!-- 显示大图部分 -->
<div class="modal fade bs-example-modal-lg text-center" id="imgModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" >
	<div class="modal-dialog modal-lg" ><!-- style="display: inline-block; width: auto;" -->
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title" id="modalLabel"></h4>
			</div>
			<img alt="暂无图片" id="imgInModalID" src="" width="90%" >
		</div>
	</div>
</div>

【注意点一】图片只设置宽度,这样就能等比例的放大了


②点击查看大图部分

<span><a href="javascript:void(0);" οnclick="showBigImg('${pro.pictrue}','${pro.proName }')" >查看大图</a></span>
我这里是遍历取出值的,所以要输入图片地址和图片名称到函数里


二、jquery

// 查看大图
function showBigImg( pictrue, name){
	$("#modalLabel").text(name);
	$("#imgInModalID").attr("src", getContextPath()+"/images/"+pictrue);
	$("#imgModal").modal('show');
	//alert(pictrue +" "+name);
}
//jquery获得path路径
function getContextPath() {
	var pathName = document.location.pathname;
	var index = pathName.substr(1).indexOf("/");
	var result = pathName.substr(0,index+1);
	return result;
}



  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值