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://aqpgk.com/article/gpegid.html">http://aqpgk.com/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/cdcooce.html">买单吧老是服务器迷茫是怎么回事?(无忧考吧登进去服务器地址连接失败是怎么回事?)</a>
</li><li>
<a href="/article/cddhhge.html">Linux下简单执行Jar包的方法(linux执行jar)</a>
</li><li>
<a href="/article/cdcoops.html">查看Linux系统负载:一招妙招省时省力(查看linux负载)</a>
</li><li>
<a href="/article/cdcooep.html">创新互联小程序教程:微信小程序API画面录制器·WebGL画面录制器实例</a>
</li><li>
<a href="/article/cdcoopd.html">电信主机托管费用</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="https://www.cdcxhl.com/sosuo.html" title="关键词优化排名" target="_blank">关键词优化排名</a></li><li><a href="http://www.bjzptech.com/" title="大悟县宗玛商贸" target="_blank">大悟县宗玛商贸</a></li><li><a href="https://www.cdcxhl.com/google.html" title="Google外贸推广" target="_blank">Google外贸推广</a></li><li><a href="http://www.kswcd.com/" title="网站定制" target="_blank">网站定制</a></li><li><a href="http://www.abtjsn.com/" title="昆明网站建设" target="_blank">昆明网站建设</a></li><li><a href="http://www.sfqfh.com/" title="昆明户外餐具" target="_blank">昆明户外餐具</a></li><li><a href="http://www.hantingcb.com/" 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.aqpgk.com</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备2025168279号-11</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>