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>
                                                文章位置:<a href="http://scyingshan.cn/article/gpegid.html">http://scyingshan.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/dgdpicd.html">外部样式上css格式 使用外部css样式文件的正确格式是</a>
                                                            </li><li>
                                                                <a href="/article/dgdpieg.html">关于linux命令上sftp的信息</a>
                                                            </li><li>
                                                                <a href="/article/dgdpigg.html">mysqlurl怎么取 mysql数据库的url</a>
                                                            </li><li>
                                                                <a href="/article/dgdpigi.html">jquery折叠菜单插件 jquery实现折叠菜单</a>
                                                            </li><li>
                                                                <a href="/article/dgdpigc.html">html5大学 html5值得学吗</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://www.cdkjz.cn/fangan/yiyao/" title="医药医疗网站建设方案" target="_blank">医药医疗网站建设方案</a></li><li><a href="http://www.scbaiwuyu.cn/" title="四川白乌鱼" target="_blank">四川白乌鱼</a></li><li><a href="http://www.cddcz.com/" title="成都网站建设" target="_blank">成都网站建设</a></li><li><a href="http://www.cqcxhl.com/" title="重庆网站制作" target="_blank">重庆网站制作</a></li><li><a href="https://www.scvps.cn/services/ssl/" title="SSL证书" target="_blank">SSL证书</a></li><li><a href="http://m.cdxwcx.com/wenjiang.html" title="温江电信机房" target="_blank">温江电信机房</a></li><li><a href="http://www.cdxwcx.cn/tuoguan/deyang.html" 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.scyingshan.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号-24</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>