jQuery/AJAX - 嵌套函数。克隆&库丰
我正在使用 Cufon,这是一个非常简单的脚本,可以将字体更改为画布。
此代码更改 H1 标题:
Cufon.replace('h1', { fontFamily: 'SuperMegaArial2010' });
一切正常,但我正在克隆一组项目(其中有一些带有标题的列表):
jQuery('ul.myList').clone();
并且 cufon 字体替换不适用于克隆的项目。
如何改变这一点?为什么会发生这种情况?
[编辑]
好吧,这会很复杂。我正在克隆我的列表,以便它将作为 Quicksand 的第二个列表。它有效,但库丰却无效。
jQuery('document').ready(function(){
//create a clone of the full list of elements and extract 'li' elements
//in order to use it as the 'second' list for quicksand
var cache_list = jQuery('ul.myList').clone();
//Add on click event handler to the 'Show Everything' button
jQuery('ul.myList li a[data-value=Everything]').click(function(e) {
//Call quicksand on the original works_list list(the one visible to the user)
//pass to it all the 'li' elements from the cached clone
//since we want to display them all
jQuery('.myList').quicksand( cache_list.find('li'), {
duration: 500,
});
jQuery('ul.myList li a[data-value=funny]').click(function(e) {
jQuery('.myList').quicksand( cache_list.find('li[data-value=funny]'), {
duration: 500,
});
e.preventDefault();
});
});
这段代码在 Cufon 之后执行了很长时间,我尝试在上面的代码之前的同一个文件中再次添加 cufon 替换 js 代码,但没有帮助。
I'm using Cufon, it's a very simple script changing fonts into canvas.
This code changes H1 headers:
Cufon.replace('h1', { fontFamily: 'SuperMegaArial2010' });
Everything works fine, but I'm cloning a set of items (a few lists with headers in them):
jQuery('ul.myList').clone();
And the cufon font replacement doesn't work for the cloned items.
How to change that? Why does it happen?
[edit]
Ok, it's going to be complicated. I'm cloning my list so it will work as a second list for Quicksand. And it works, but Cufon doesn't.
jQuery('document').ready(function(){
//create a clone of the full list of elements and extract 'li' elements
//in order to use it as the 'second' list for quicksand
var cache_list = jQuery('ul.myList').clone();
//Add on click event handler to the 'Show Everything' button
jQuery('ul.myList li a[data-value=Everything]').click(function(e) {
//Call quicksand on the original works_list list(the one visible to the user)
//pass to it all the 'li' elements from the cached clone
//since we want to display them all
jQuery('.myList').quicksand( cache_list.find('li'), {
duration: 500,
});
jQuery('ul.myList li a[data-value=funny]').click(function(e) {
jQuery('.myList').quicksand( cache_list.find('li[data-value=funny]'), {
duration: 500,
});
e.preventDefault();
});
});
This code is being executed long time after Cufon, I've tried adding cufon replace js code once again in the same file before the code above, but didn't help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您在 cufon 调用后克隆了这些项目。这是因为当调用 cufon 时,您的项目不存在。您只需再次调用 cufon 即可发挥其魔力。
I'm assuming you cloned the items after your cufon call. This is because when cufon is called your items don't exist. You could simply call cufon again for it to do it's magic.