十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
首先在官网下载最新版的fancyBox(一定要去最新网站,以前依赖的jquery版本偏低),附上链接:
成都创新互联公司专注于企业营销型网站、网站重做改版、建湖网站定制设计、自适应品牌网站建设、H5场景定制、成都商城网站开发、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为建湖等各大城市提供网站开发制作服务。
http://fancyapps.com/fancybox/3/
然后在项目中引用jquery,然后在引用jquery.fancybox.min.css和jquery.fancybox.min.js。
如果需要动画和鼠标滚轮滚动效果还可以引入他提供的相关工具文件。
1.你可以通过链接.css和.js在你的html文件来安装fancyBox 。确保您也加载了jQuery库。以下是用作示例的基本HTML模板
<!DOCTYPE html>我的页面</ title> <! - CSS - > <link rel =“stylesheet”type =“text / css”href =“jquery.fancybox.min.css”> </ HEAD> <BODY> <! - 您的HTML内容到这里 - > <! - JS - > <script src =“// code.jquery.com/jquery-3.2.1.min.js”> </ script> <script src =“jquery.fancybox.min.js”> </ script> </ BODY> </ HTML></pre></div><p>2.通过通过Bower或npm安装工具安装</p><div><pre># Bower bower install fancybox --save # NPM npm install @fancyapps/fancybox --save</pre></div><p>3.项目中通过外部引用,一般放在lib文件夹下(我采用的是这种方法)</p><p>在lib下新建一个文件目录fancy文件夹,然后引入下载好的.js和.css,在gulpfile.js添加自动化打包压缩任务,放在css目录中的lib.min.css和lib.min.js,在入口index.html中引入压缩后的文件。</p><p>以本fancyBox插件举例:</p><div><pre>gulp.task('build-lib-js', ['build-clean-third-lib-js'], function () { var thirdLibJs = gulp.src([ //外部引用js './lib/fancybox/jquery.fancybox.min.js', ]) .pipe(uglify()) .pipe(concat('lib.min.js', {newLine: '\r\n'})) .pipe(gulp.dest('js')); return merge.apply(null, thirdLibJs); }); gulp.task('build-lib-css', ['build-clean-lib-css'], function () { var thirdLibCss = gulp.src([ //外部引用css './lib/fancybox/jquery.fancybox.min.css' ]) .pipe(concat('lib.min.css', {newLine: '\r\n'})) //放在哪个文件中 .pipe(gulp.dest('css'));//打包输出目录(在哪个目录下) return merge.apply(null, thirdLibCss); });</pre></div><p>封装在angular自定义组件中</p><p>html模块:</p><div><pre><img-box img-url="'xxxxxx.png'" img-></img-box></pre></div><p>directive.js模块:</p><div><pre>var appModule = angular.module('app.core'); appModule.directive('imgBox',imgBox);</pre></div><div><pre>function imgBox() { return { restrict:'AE', transclude:true, scope:{ imgUrl:"=", imgStyle:'=' }, template:'<a class="imageBox" href="{{imgUrl}}" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-fancybox><img src="{{imgUrl}}" th:src="${cdn.url('+"'{{imgUrl}}'"+')}" /></a>', link:function (scope,elem,attrs) { $(".imageBox").fancybox(); }, } }</pre></div><p>官方写法:</p><div><pre><a href="/upload/otherpic56/66509.jpg" data-fancybox="images" data-width="2048" data-height="1365"> <img src="/upload/otherpic56/66510.jpg" /> </a> <a href="/upload/otherpic56/66511.jpg" data-fancybox="images" data-width="2048" data-height="1366"> <img src="/upload/otherpic56/66513.jpg" /> </a> <a href="/upload/otherpic56/66527.jpg" data-fancybox="images" data-width="2048" data-height="1365"> <img src="/upload/otherpic56/66539.jpg" /> </a></pre></div><p>标注:data-fancybox使用图片预览插件,三个值都为images表示在一个图片组内 data-width data-height 图像的真实宽高度 data-caption 标题信息</p><p>启用方法: </p><div><pre><script type="text/javascript"> $("[data-fancybox]").fancybox({ // Options will go here }); </script></pre></div><p>遇到的问题:</p><p>1.如果使用低版本的图片预览插件,回报Cannot read property 'msie' of undefined的错,原因低版本似乎使用$ .browser方法,但是从jQuery 1.9起已被删除</p><p>2.在template或者templateUrl要使用html中传入的imgUrl值,不能直接使用imgUrl或者scope.imgUrl获取。</p><p>方法:</p><div><pre>template:'<a class="imageBox" href="{{imgUrl}}" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-fancybox><img src="{{imgUrl}}" th:src="${cdn.url('+"'{{imgUrl}}'"+')}" /></a>'</pre></div><p>或者</p><div><pre>template:'<a class="imageBox" ng-href="{{imgUrl}}" rel="external nofollow" rel="external nofollow" rel="external nofollow" data-fancybox><img ng-src="{{imgUrl}}" th:src="${cdn.url('+"'{{imgUrl}}'"+')}" /></a>'</pre></div><p>后面的th:src可以不用拼接,如果你项目中是用cdn上的资源图片,可以使用。</p><p><strong>总结</strong></p><p>以上所述是小编给大家介绍的Angular中封装fancyBox(图片预览)遇到问题小结,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对创新互联网站的支持!</p> <br> 分享名称:Angular中封装fancyBox(图片预览)遇到问题小结 <br> 网页URL:<a href="http://www.zsjierui.cn/article/gpegid.html">http://www.zsjierui.cn/article/gpegid.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/dgjpchg.html">关于jqcss设置多样式的信息</a> </li><li> <a href="/article/dgjpchd.html">百度小程序一直编译中 百度ai小程序</a> </li><li> <a href="/article/dgjpsod.html">jquery扇形动画 动画效果扇形展开</a> </li><li> <a href="/article/dgjpsoc.html">微信小程序分享按钮 微信小程序分享按钮怎么关闭</a> </li><li> <a href="/article/dgjpcpc.html">鼎力android 鼎力支持</a> </li> </ul> </div> </div> <footer> <div class="message"> <div class="mess container"> <p>免费获取网站建设与品牌策划方案报价</p> <span>*主要业务范围包括:高端网站建设, 集团网站建设(网站建设网站制作)找网站建设公司就上美图齐众。</span> <form action=""> <input type="text" class="ipt1" placeholder="联系人"> <input type="text" class="ipt2" placeholder="联系电话"> <textarea name="" id="" placeholder="内容描述:描述您的需求,如网站、微信、电商、APP等。"></textarea> <a href="">提交需求</a> </form> </div> </div> <div class="footA"> <div class="footAs container"> <ul> <h3>联系我们</h3> <b>028-86922220</b> <li>手机:13518219792</li> <li>地址:成都市太升南路288号锦天国际A幢1002号</li> <li class="hr1"></li> <li>24小时服务热线:028-86922220</li> </ul> <ul> <h3>网站建设服务</h3> <li>网页设计</li> <li>网站制作</li> <li>网站开发</li> </ul> <ul> <h3>网站推广服务</h3> <li>营销网站建设</li> <li>百度快速排名</li> <li>整站网站推广</li> </ul> <ul> <h3>网站运维服务</h3> <li>基础维护</li> <li>网站改版</li> <li>网站维护</li> </ul> <ul> <h3>FOLLOW US</h3> <li class="hr2"></li> <li> <dd class="fl"><img src="/Public/Home/img/ewm.png" alt=""><p>微信二维码</p></dd> <dd class="fr"><img src="/Public/Home/img/ewm.png" alt=""><p>微信二维码</p></dd> </li> </ul> </div> <div class="link container"> 友情链接: <a href="http://chengdu.cdcxhl.cn/seo/ " title="营销网站建设" target="_blank">营销网站建设</a> <a href="http://www.kswcd.com/solution/" title="网站解决方案" target="_blank">网站解决方案</a> <a href="http://www.zzdkfx.cn/" title="商场标识导视牌设计" target="_blank">商场标识导视牌设计</a> <a href="http://www.cdhuace.com/fuwu.html" title="成都名片印刷" target="_blank">成都名片印刷</a> <a href="https://www.cdcxhl.com/cqtuoguan.html" title="重庆主机托管" target="_blank">重庆主机托管</a> <a href="http://www.zsjierui.cn/" title="资阳网站建设" target="_blank">资阳网站建设</a> <a href="http://www.bzwzjz.com/serve/" title="专业网站设计" target="_blank">专业网站设计</a> <a href="http://www.scwxfdj.com/" title="四川柴油发电机维修" target="_blank">四川柴油发电机维修</a> <a href="http://chengdu.cdcxhl.com/seo/" title="成都网站排名" target="_blank">成都网站排名</a> <a href="http://www.cypth.com/" title="成都灯箱广告" target="_blank">成都灯箱广告</a> </div> </div> <div class="footB"> <div class="container"> <div class="fl"> Copyright © 2025 资阳站青羊区美图齐众设计工作室(个体工商户) 资阳网站建设公司-选网站建设公司美图齐众!专业的网站制作公司! </div> <div class="fr"> All Rights Reserved 版权所有 <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备2025119604号-1</a> </div> </div> </div> </footer> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>