RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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>
                                                URL网址:<a href="http://cqwzjz.cn/article/gpegid.html">http://cqwzjz.cn/article/gpegid.html</a>
                                            </div>
                                            <div class="hot_new">
                                                <div class="page_title clearfix">
                                                    <h3>其他资讯</h3>
                                                </div>
                                                <div class="news_list clearfix">
                                                    <ul>
                                                        <li>
                                                                <a href="/article/dcsdpdo.html">腾讯云服务器无法启动 腾讯云服务器无法启动怎么回事</a>
                                                            </li><li>
                                                                <a href="/article/dcsdpsg.html">java代码调用接口 java调用接口实现</a>
                                                            </li><li>
                                                                <a href="/article/dcsdpsp.html">linux禁止某些命令的简单介绍</a>
                                                            </li><li>
                                                                <a href="/article/dcsdjhe.html">c语言函数返回动态内存 c语言程序返回值</a>
                                                            </li><li>
                                                                <a href="/article/dcsdgii.html">php提取数据处理 php数据抓取</a>
                                                            </li>                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 底部信息 -->
<div class="footer wow fadeInUp">
    <div class="rowFluid">
        <div class="span12">
            <div class="container">
                <div class="footer_content">
                    <div class="span4 col-xm-12">
                        <div class="footer_list">
                            <div class="span6">
                                <div class="bottom_logo"><img src="/Public/Home/images/ewm.jpg" alt="微信服务号二维码" /></div>
                            </div>
                            <div class="span6 col-xm-12">
                                <div class="quick_navigation">
                                    <div class="quick_navigation_title">快速导航</div>
                                    <ul>
                                        <li><a href="http://chengdu.cdcxhl.cn/shop/
" title="成都商城开发" target="_blank">成都商城开发</a></li><li><a href="http://www.dcwzsj.com/" title="德昌麦琪建站" target="_blank">德昌麦琪建站</a></li><li><a href="http://www.cdkjz.cn/wangzhan/keyseo/" title="成都关键词SEO优化" target="_blank">成都关键词SEO优化</a></li><li><a href="http://www.cddcz.com/" title="成都网站建设" target="_blank">成都网站建设</a></li><li><a href="http://www.cqcxhl.com/service/" title="品牌网站建设" target="_blank">品牌网站建设</a></li><li><a href="http://www.cxjianzhan.com/" title="网站建设公司" target="_blank">网站建设公司</a></li><li><a href="http://www.gdcrkj.cn/" title="德阳东方电机技改" target="_blank">德阳东方电机技改</a></li>                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="span4 col-xm-6 col-xs-12">
                        <div class="footer_list">
                            <div class="footer_link">
                                <div class="footer_link_title">友情链接</div>
                                <ul id="frientLinks">
                                    <a href="https://www.cdcxhl.com/" title="网站制作" target="_blank">网站制作</a>
                                    <a href="https://www.cdcxhl.com/" title="网站建设" target="_blank">网站建设</a>
                                    <a href="https://www.cdxwcx.com/tuiguang/" title="成都网络推广" target="_blank">网络推广</a>
                                    <a href="http://seo.cdkjz.cn/" title="成都网站推广" target="_blank">网站推广</a>
                                    <a href="https://www.cdcxhl.com/xiaochengx.html" title="成都微信小程序开发" target="_blank">小程序开发</a>
                                    <a href="https://www.cdcxhl.com/menu.html" title="创新互联网站栏目导航" target="_blank">网站导航</a>
                                </ul>
                                <div class="footer_link_title">网站建设</div>
                                <ul id="frientLinks">
                                    <li><a href="/">重庆大橙子建站</a></li>
                                    <li><a href="https://www.cdcxhl.com/menu.html" title="创新互联网站栏目导航" target="_blank">网站导航</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="span4 col-xm-6 col-xs-12">
                        <div class="footer_list">
                            <div class="footer_cotact">
                                <div class="footer_cotact_title">联系方式</div>
                                <ul>
                                    <li><span class="footer_cotact_type">企业:</span><span class="footer_cotact_content">青羊区大橙子信息咨询工作室</span></li>
                                    <li><span class="footer_cotact_type">地址:</span><span class="footer_cotact_content">成都市青羊区太升南路288号</span></li>
                                    <li><span class="footer_cotact_type">电话:</span><span class="footer_cotact_content"><a href="tel:18980820575" class="call">18980820575</a></span></li>
                                    <li><span class="footer_cotact_type">网址:</span><span class="footer_cotact_content"><a href="/" title="重庆网站建设">www.cqwzjz.cn</a></span></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="copyright">
                <p>公司名称:青羊区大橙子信息咨询工作室   联系电话:18980820575</p>
                <p><a href="http://beian.miit.gov.cn" target="_blank" rel="nofollow">网站备案号:蜀ICP备2022028542号-22</a></p>
                <p>重庆大橙子建站 重庆网站建设 重庆网站设计 重庆网站制作 <a href="http://www.cdxwcx.cn/" target="_blank">成都做网站</a></p>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
    $(".technical_support_box_z_info_box 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>