Cufon 嵌套悬停问题
当使用多个列表和悬停状态时,“父”Cufon 样式将替换子项。在以下示例中,当您将鼠标悬停在“第二级”链接时,它将被不同的权重替换。
我是否可以设置一个选项以使嵌套样式保持不变,或者这是 Cufon 中的错误/限制?
<ul>
<li><a href="#">Top Level</a></li>
<li><a href="#">Top Level</a></li>
<li><a href="#">Top Level</a><ul>
<li><a href="#">Second Level</a></li>
<li><a href="#">Second Level</a></li>
<li><a href="#">Second Level</a></li>
</ul>
<li><a href="#">Top Level</a></li>
<li><a href="#">Top Level</a></li>
</ul>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://github.com/sorccu/cufon/raw/master/js/cufon.js"></script>
<script type="text/javascript" src="http://github.com/sorccu/cufon/raw/master/fonts/Vegur.font.js"></script>
<script type="text/javascript">
Cufon.replace('ul li a',{hover: true, fontWeight: 200});
Cufon.replace('ul li ul a',{hover: true, fontWeight: 700});
</script>
When using multiple lists and hover states the 'parent' Cufon style replaces the child. In the following example, when you hover the Second Level link it will be replaced by a different weight.
Is there an option I can set so that the nested style stays the same or is this a bug/limitation within Cufon?
<ul>
<li><a href="#">Top Level</a></li>
<li><a href="#">Top Level</a></li>
<li><a href="#">Top Level</a><ul>
<li><a href="#">Second Level</a></li>
<li><a href="#">Second Level</a></li>
<li><a href="#">Second Level</a></li>
</ul>
<li><a href="#">Top Level</a></li>
<li><a href="#">Top Level</a></li>
</ul>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://github.com/sorccu/cufon/raw/master/js/cufon.js"></script>
<script type="text/javascript" src="http://github.com/sorccu/cufon/raw/master/fonts/Vegur.font.js"></script>
<script type="text/javascript">
Cufon.replace('ul li a',{hover: true, fontWeight: 200});
Cufon.replace('ul li ul a',{hover: true, fontWeight: 700});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个解决方案:使用不会在元素集重叠的地方创建匹配的选择器。
解释为什么您的选择器 + Cufon 会产生问题
该问题似乎源于您的选择器。
这意味着您实际上已为二级
标签指定了两次
fontWeight
。遗憾的是,Cufon 似乎不仅仅应用具有最高 CSS 特异性 因此,该行为将取决于 Cufon 内部如何存储像这样的多个匹配项。经过几次测试后,Cufon 似乎以与您调用
replace()
语句相反的顺序应用样式。例如,如果您这样做,
所有链接将显示为蓝色,并且二级链接的 fontWeight 为 700直到悬停,然后他们得到 fontWeight 200 设置。
如果您切换顺序,
最初所有链接的 fontWeight 都会为 200,当悬停时,第二级链接将设置为 700。
您注意到行为会根据您的调用顺序而变化。
不确定性
我不认识Cufon,也不太明白你想做什么。特别是我不确定您是否打算像您一样使用传递给 Cufon 的选项,或者您实际上是否打算在悬停时设置 fontWeight 。
之间存在差异。
和
第一个将
fontWeight
设置为 200,如果元素悬停,也会将 fontWeight 设置为 200,只有当fontWeight
在与此同时。后者仅在悬停时将元素的样式更改为
fontWeight
200,并在元素不再悬停时删除粗细。我不确定您打算使用哪一个。
Solution first: Use selectors which don't create matches where the set of elements overlap.
Explanation why your selectors + Cufon create problems
The problem seems to originate from you selectors.
This means you have actually specified the
fontWeight
twice for the second-level<a>
-tags. Sadly Cufon doesn't seem to apply only the expression which has the highest CSS specificity thus the behavior will depend on how Cufon internally stores multiple matches like this one.After a few tests it seems that Cufon applies the styles in the reverse order you call the
replace()
statements in. e.g.If you do
All links will appear blue and the 2nd-level-links have fontWeight 700 until hovered, then they get fontWeight 200 set.
If you switch the order
Initially all links will have fontWeight 200, the 2nd-level-links will get 700 set when hovered.
You notice the behavior changes depending on the order of your calls.
Uncertainty
I don't know Cufon and I don't really understand what you are trying to do. Especially I'm not sure if you mean to use the options passed in to Cufon as you do or if you actually mean to just set fontWeight when hovering.
There is a difference between
and
The first sets
fontWeight
to 200 and if the element is hovered also sets the fontWeight to 200, which would only be noticeable if thefontWeight
changed in the meantime.The latter only changes the style of the element to
fontWeight
200 while hovered and removes the weight when the element is no longer hovered.I'm not sure which one you intend to use.