微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 为花式框添加标题

嗨,你可能认为这是一个愚蠢的问题,但我正在尝试将标题添加到花哨的方框2.我对 javascript知之甚少,但在我的html底部有这个
<script type="text/javascript">
$(document).ready(function() {
    $(".fancybox").fancybox();
});
</script>

如果我尝试加入

$(".fancybox")
.attr('rel','gallery')
.fancybox({
    beforeLoad: function() {
        this.title = $(this.element).attr('caption');
}
});

我得到各种语法错误.

网站是:http://bit.ly/Wan5kr

解决方法

您当前的脚本是:
$(document).ready(function() {
  $(".fancybox").fancybox({
   helpers : { 
    title : { type : 'inside' }
   },// helpers
   afterLoad : function() {
    this.title = (this.title ? '' + this.title + '<br />' : '') + 'Image ' + (this.index + 1) + ' of ' + this.group.length;
   } // afterLoad
  }); // fancybox
 }); // ready

……但应该是(如果你不想要“第1页,共6页”):

$(document).ready(function() {
  $(".fancybox").fancybox({
   helpers : { 
    title : { type : 'inside' }
   } // helpers
  }); // fancybox
 }); // ready

另一方面,如果您更喜欢使用标题属性(因为当您悬停图像时标题显示为工具提示)更改标题,如标题所示

<a href="images/gallery/large/wing-back-chair.jpg" caption="Early 1900'....." rel="Sold" class="fancybox"><img width="304" height="350" alt="Winged back chair and ottoman" src="images/gallery/tn/wing-back-chair.jpg"></a>

并使用此脚本

$(document).ready(function() {
  $(".fancybox").fancybox({
   helpers : { 
    title : { type : 'inside' }
   },// helpers
   beforeLoad: function() {
    this.title = $(this.element).attr('caption');
   }
  }); // fancybox
 }); // ready

原文地址:https://www.jb51.cc/jquery/179073.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐