sta*_*ler 3 javascript jquery fancybox
我正在尝试使用带有fancybox 2的图像alt标签中的标题和"标题"...出于某种原因我似乎无法工作......
$('.fancybox').fancybox({
beforeShow : function() {
this.title = '<div class="new-title-title">' + $(this).attr('title') + '</div><div class="new-title-alt">' + $(this).children('img:first').attr('alt') + '</div>';
},
helpers : {
title: {
type: 'inner',
beforeShow: function(opts) {
console.log('beforeShow title helper');
},
},
},
});
Run Code Online (Sandbox Code Playgroud)
来自$(this).attr('title')的标题工作,来自$(this)的字幕.儿童('img:first').attr('alt')说未定义...我知道我必须遗漏一些简单的东西...
如果我的理解没错,你想要的fancybox标题作为组合title中的属性a标签+中alt的属性img标签.
如果上面的说法是正确的,那么就像html一样
<a class="fancybox" href="images/01.jpg" title="title anchor 01" ><img src="images/01t.jpg" alt="alt image 01" /></a>
Run Code Online (Sandbox Code Playgroud)
fancybox标题应该说" title anchor 01 alt image 01 "
你用这个脚本做到这一点:
$(document).ready(function() {
$(".fancybox").fancybox({
helpers : {
title: { type: 'inside'}
},
afterLoad: function(){
this.title = this.title + ' ' + $(this.element).find('img').attr('alt');
}
}); // fancybox
}); // ready
Run Code Online (Sandbox Code Playgroud)