JavaScript 生成的文本消失(Cufon 和 Clone)
我有一个列表:
<ul>
<li><h2>Header</h2><p>Text</p></li>
<li><h2>Header</h2><p>Text</p></li>
<li><h2>Header</h2><p>Text</p></li>
</ul>
标题文本显示为 Cufon 生成的画布。
我正在克隆我的列表并使用第二个列表作为流沙脚本的替代品。
一切都按预期工作,但排序后标题不可见(但画布仍然在那里!)。
如何解决这个问题?
实例:
http://bartekka.ayz.pl/quicksand/
(每个“Cufon Title”都会消失)单击链接后,删除 Cufon.now() 会有所帮助,但这不是答案,因为我的项目需要这部分代码)
I have a list:
<ul>
<li><h2>Header</h2><p>Text</p></li>
<li><h2>Header</h2><p>Text</p></li>
<li><h2>Header</h2><p>Text</p></li>
</ul>
Header text is being displayed as Cufon generated canvas.
I'm cloning my list and using the second one as replacement for Quicksand script.
Everything works like expected, but the headers are invisible after sorting (but the canvases are still there!).
How to fix that?
Live example:
http://bartekka.ayz.pl/quicksand/
(every "Cufon Title" disappears after clicking a link, removing Cufon.now() helps, but this is not an answer since this part of code is required in my project)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 Cufon 创建元素的方式总是给我带来麻烦。我所做的就是在与 javascript 交互后重新绘制文本。最快的方法是调用 Cufon.refresh() ,它将重绘页面上的所有 cufon 项目。或者,您可以专门针对它们。
当我这样做时,我倾向于创建一个函数来完成我将更改的 cufon 项目的初始绘制。然后我可以在我的排序(或其他)js 完成后回忆起该函数。
HTH :)
编辑评论
当然,不用担心:)
您正在使用的排序插件具有回调功能,因此您可以执行以下操作:
编辑2
对 - 发现一些非常有趣的东西:Quicksand 有一个用于此类目的的选项。试试这个(注意 - 我已将你的四个函数压缩为 1 个,以便于测试 - 也许这是你可以使用的东西?):
认为可以做到(在 Chrome 和 FF 中对我有用)。如果您想将其添加到原始函数中,
enhancement
调用非常重要。手指交叉!
This is because of the way Cufon creates elements - always causes trouble for me. What I do is redraw the text after any javascript interaction with it. Quickest way is to call
Cufon.refresh()
which will redraw all cufon items on the page. Alternatively you can target them specifically.When I do this I tend to create a function to do the initial drawing of cufon items I will alter. Then I can just recall that function after my sorting (or whatever) js is complete.
HTH :)
EDIT in response to comment
Sure, not worries :)
The sorting plugin you are using has a callback feature so you can just do this:
EDIT 2
Right - found something very interesting: Quicksand has an option for just such a purpose. Try this (note - I've compressed your four functions into 1 for ease of testing - possibly this is something you can use?):
Think that will do it (works for me in Chrome and FF). The
enhancement
call is the important one if you want to add it to your original functions.Fingers crossed!
验证您的 HTML。在很多地方都有未知的
data-id
和data-value
属性存在问题,例如:Validate your HTML. There is a problem with unknown
data-id
anddata-value
attributes in quite a few places e.g.:<li data-id="1" data-value="Image">