格式化FancyBox的标题

时间:2011-05-18 14:48:43

标签: javascript jquery fancybox

我根本不知道javascript,但我正在尝试使用FancyBox格式化我的图片的标题/标题。在我的<a>标签的title属性中,我写了一个人名,专业和职业。我希望他们的名字显示在一行,然后主要和职业可以在下一行。例如:

Joe Smith,BS '02
专业:企业社会责任,职业:零售经理

我知道我无法进入title="",所以在我的javascript函数中有一个简单的方法吗?我希望我可以将我的id属性设置为该人的名字并在我的函数中调用它,然后将标题设置为其余部分,但这似乎不起作用。

这是当前功能正常,只需要以某种方式分割我的标题:

("a[rel=cdfs]").fancybox({

            'transitionIn'      : 'elastic',
            'transitionOut'     : 'elastic',
            'titlePosition'     : 'over',
            'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
                return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '<br/><p align="right" >Image ' + (currentIndex + 1) + ' / ' + currentArray.length + '</p></span>';
            }
        });

感谢您的任何想法或输入!我很感激:)

1 个答案:

答案 0 :(得分:3)

你可以用两行来打破你的头衔:

'titleFormat': function(title, currentArray, currentIndex, currentOpts){
temp=title.split('|');
if(!temp[1]){temp[1]=""};
return '<div>'+temp[0]+'</div><div>'+temp[1]+'</div>'

},

正如你所看到的,我通过添加'|'来分割标题字符,需要添加到标题文本中,但您可以采用不同的方式。此外,在这个简单的例子中,格式化如背景等会丢失,但您可以轻松修复它。

祝你好运

ķ