为啥要做捏?最近一个项目用到了类似于模态框的 点击按钮 出现图片或html页面的功能,琢磨很久,不知道怎么下手,然后请教了一个前端高手,向我推荐了fancybox,在这里,也很由心的感谢那位前端高手,前前后后帮了我好多。不说多了,下面说一下用法吧,按照这个写,应该就没问题了。
1、引用fancybox插件相关的js和css文件
注意版本的问题
2、在需要用到fancybox插件的页面中引入相关的js和css
<link href="${ctx}/assets/vendors/fancybox/jquery.fancybox.css" media="all" rel="stylesheet" type="text/css"/>
<script type="application/javascript" src="${ctx}/assets/vendors/fancybox/jquery.fancybox.js"></script>
3、设置页面的高度和宽度
$('.fancybox').fancybox({
width: '90%',
minHeight: '90%',
});
2和3步我都是在sitemesh的装饰页面中进行引入的
4、在需要使用fancybox的页面中使用fancybox fancybox.iframe的class样式,比如:
<a type="button" class="btn btn-warning btn-xs applyButton fancybox fancybox.iframe" href="${ctx}/task/getGKByDataNo?dataNo='+data.data[i].dataNo+'">查看工卡</a>
5、至此,应该就可以看到fancybox的窗口了,有点像模态框,不过比模态框好看好用多了。