028-86922220
建站资讯

网站建设资讯

为你提供网站建设行业资讯、网站优化知识、主机域名邮箱、网站开发常见问题等。

Angular中封装fancyBox(图片预览)遇到问题小结

首先在官网下载最新版的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>
            浏览路径:<a href="http://whjierui.cn/article/gpegid.html">http://whjierui.cn/article/gpegid.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dgooccc.html">linux命令练习软件 linux 命令app</a>
                </li><li>
                    <a href="/article/dgoocoh.html">css为单独连接添加样式 css中设置连接的四种状态</a>
                </li><li>
                    <a href="/article/dgooccj.html">jquery浮动窗口 jquery 滑动显示</a>
                </li><li>
                    <a href="/article/dgoocec.html">html5背景扩充 html5中怎么设置背景的大小</a>
                </li><li>
                    <a href="/article/dgoodes.html">mysql表怎么做 mysql怎么制作表格</a>
                </li>        </ul>
    </div>
</div>
<footer>
    <div class="foot-top">
        <ul>
            <li>
                <div class="title">关于美图云海</div>
                <div class="tbox">
                    <div class="txt">
                        美图云海专注于网站建设、小程序开发,
                        <br /> 用心做好每一个网站,懂您所需、做您所想!
                        <br /> 我们比其他网络公司做的更好、做的更多,
                        <br /> 为客户创造更大的价值,让客户更省心!
                    </div>
                    <a rel="nofollow" href="javascript:;" class="more">MORE</a>
                </div>
            </li>
            <li>
                <div class="title">相关专题</div>
                <div class="tbox">
                    <a href="javascript:;" class="link">企业官网定制</a>
                    <a href="javascript:;" class="link">小程序开发</a>
                    <a href="javascript:;" class="link">品牌网站设计</a>
                    <a href="javascript:;" class="link">网站建设标签</a>
                    <a href="javascript:;" class="link">乐山网站建设</a>
                    <a href="javascript:;" class="link">高端网站设计</a>
                    <a href="javascript:;" class="link">公司做网站</a>
                </div>
            </li>
            <li>
                <div class="title">凭什么选择我们</div>
                <div class="tbox">
                    <a class="link">专业设计团队</a>
                    <a class="link">快速响应服务</a>
                    <a class="link">7个软件著作权</a>
                    <a class="link">已服务3000+客户</a>
                    <a class="link">项目检测具体全面</a>
                    <a class="link">技术研发能力强劲</a>
                    <a class="link">深度符合SEO优化</a>
                    <a class="link">15项设计奖项</a>
                    <a class="link">完善的制作流程</a>
                    <a class="link">售后服务让您省心</a>
                </div>
            </li>
            <li>
                <div class="title">网站设计案例</div>
                <div class="tbox">
                    <ul>
                        <li>
                            <a href="javascript:;" target="_blank">
                                <div class="img"><img src="/Public/Home/images/gebaili.jpg" alt="哥百利" />
                                </div>
                                <div class="tboxs">
                                    <div class="t1">哥百利</div>
                                    <div class="t2">家具研发、设计、生产、服务为一体的专业实木家具订做企业</div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <a href="javascript:;" target="_blank">
                                <div class="img"><img src="/Public/Home/images/cdshujin.jpg" alt="蜀锦在线" /></div>
                                <div class="tboxs">
                                    <div class="t1">蜀锦在线</div>
                                    <div class="t2">汽车行业网站建设</div>
                                </div>
                            </a>
                        </li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
    <div class="foot-center">
        <ul>
            <li>
                <div class="f-ewm"><img alt="美图云海微信公众号" src="/Public/Home/images/ewm.jpg" /></div>
                <div class="tbox ewm">
                    <div class="t1">扫一扫关注</div>
                    <div class="t2">专业团队为您解答</div>
                </div>
            </li>
            <li>
                <div class="tbox tel">
                    <div class="t1">电话/邮箱</div>
                    <div class="t2">400-028-6601 / 028-86922220<br>631063699@qq.com</div>
                </div>
            </li>
            <li>
                <div class="tbox sz">
                    <div class="t1">成都(总部)</div>
                    <div class="t2">成华区 双林路22号仁禾商务楼5F<br> 大客户专线:13518219792
                    </div>
                </div>
            </li>
            <li>
                <div class="tbox gz">
                    <div class="t1">网站建设(乐山站)</div>
                    <div class="t2">
                        乐山市市中区瑞祥路一段1507号
                        <br /> 028-86922220
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="foot-button">
        <div class="link-box" style="width:100%;float:none;">
            <div class="a-box"></div>
            <div style="border-top:1px solid #ebebeb;font-size:12px;color:#666666;line-height:2;padding-top:20px;margin-top:20px;">
                业务范围包括企业网站建设、商城系统开发、品牌网站设计、旅游网站制作、英文外贸网站、教育培训门户网站开发、微信手机移动端开发、响应式网站建设、微信小程序开发、APP定制和其他类型网站定制等。
                <br>服务区域包括成都市锦江区、青羊区、武侯区、金牛区、成华区、龙泉驿、温江、新都、高新区、成都市以及全国各地接受异地服务商的公司企业或者机构。
                <br>
                <div class="a-box"><span><b>友情链接</b></span>
                    <a href="http://www.ty2auto.com/" title="添翼二手车鉴定" target="_blank">添翼二手车鉴定</a><a href="http://www.kmjike.cn/" title="成发金汇" target="_blank">成发金汇</a><a href="http://www.cdxwcx.cn/" title="成都网站建设" target="_blank">成都网站建设</a><a href="http://www.cxjianzhan.com/" title="网络营销推广" target="_blank">网络营销推广</a><a href="https://www.xwcx.net/zuyong.html" title="成都主机租用" target="_blank">成都主机租用</a><a href="http://m.cdcxhl.com/muban.html" title="成都模版网站建设" target="_blank">成都模版网站建设</a><a href="https://www.cdcxhl.com/mianfei/zuo/chengdu.html" title="成都免费做网站" target="_blank">成都免费做网站</a><a href="http://chengdu.cdxwcx.cn/wangzhan/" title="手机网站制作" target="_blank">手机网站制作</a><a href="http://www.zhuanlizhuanrang.cn/" title="四川审计公司" target="_blank">四川审计公司</a><a href="http://www.ncjierui.cn/" title="彭山网站制作" target="_blank">彭山网站制作</a>                </div>
            </div>
            <div class="copyright">©2025 青羊区美图云海设计工作室(个体工商户)乐山站   蜀ICP备19037934号</div>
        </div>
    </div>
</footer>
<div class="fixed-contact-wrap show">
    <ul class="item-list clearfix">
        <li class="phone">
            <a rel="nofollow" target="_blank" href="tel:028-86922220"><i
                    class="icon"></i><strong>028-86922220</strong></a>
        </li>
        <li class="qq">
            <a rel="nofollow" target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes"><i
                    class="icon"></i><strong> 244261566</strong></a>
        </li>
        <li class="back-top">
            <a href="#" rel="nofollow" class="back-to-top"><i class="icon"></i><strong> 回到顶部</strong></a>
        </li>
    </ul>
</div>
<script type="text/javascript">
    //右侧联系我们悬浮窗
    $(".fixed-contact-wrap").hover(function () {
        $(this).addClass("active");
    }, function () {
        $(this).removeClass("active");
    })
    function show_phone_menu() {
        $(".right-side ul").toggle();
    }
</script>

</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>