Cufon 嵌套悬停问题

发布于 2024-08-12 19:29:39 字数 1256 浏览 8 评论 0原文

当使用多个列表和悬停状态时,“父”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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往昔成烟 2024-08-19 19:29:40

第一个解决方案:使用不会在元素集重叠的地方创建匹配的选择器。

//selects only 1st level links
Cufon.replace('ul:has(ul) > li   a', { hover: true, fontWeight: 200});
//selects only 2nd level links
Cufon.replace('ul:not(:has(ul)) a', { hover: true, fontWeight: 700});


解释为什么您的选择器 + Cufon 会产生问题

该问题似乎源于您的选择器。

ul li a --> selects all 8 occurrences of <a>
ul li ul a --> selects only the 3 second-level occurrences of <a>

这意味着您实际上已为二级 标签指定了两次 fontWeight。遗憾的是,Cufon 似乎不仅仅应用具有最高 CSS 特异性 因此,该行为将取决于 Cufon 内部如何存储像这样的多个匹配项。

经过几次测试后,Cufon 似乎以与您调用 replace() 语句相反的顺序应用样式。例如,

如果您这样做,

Cufon.replace('ul li a',{hover: true, fontWeight: 200});
Cufon.replace('ul li ul a',{hover: true, fontWeight: 700});

所有链接将显示为蓝色,并且二级链接的 fontWeight 为 700直到悬停,然后他们得到 fontWeight 200 设置。

如果您切换顺序,

Cufon.replace('ul li ul a',{hover: true, fontWeight: 700});
Cufon.replace('ul li a',{hover: true, fontWeight: 200});

最初所有链接的 fontWeight 都会为 200,当悬停时,第二级链接将设置为 700。

您注意到行为会根据您的调用顺序而变化。


不确定性

我不认识Cufon,也不太明白你想做什么。特别是我不确定您是否打算像您一样使用传递给 Cufon 的选项,或者您实际上是否打算在悬停时设置 fontWeight 。

之间存在差异。

Cufon.replace('ul li a', { hover: true, fontWeight: 200 } );

Cufon.replace('ul li a', {
    hover: { fontWeight: 200 }
});

第一个将 fontWeight 设置为 200,如果元素悬停,也会将 fontWeight 设置为 200,只有当 fontWeight 在与此同时。

后者仅在悬停时将元素的样式更改为 fontWeight 200,并在元素不再悬停时删除粗细。

我不确定您打算使用哪一个。

Solution first: Use selectors which don't create matches where the set of elements overlap.

//selects only 1st level links
Cufon.replace('ul:has(ul) > li   a', { hover: true, fontWeight: 200});
//selects only 2nd level links
Cufon.replace('ul:not(:has(ul)) a', { hover: true, fontWeight: 700});


Explanation why your selectors + Cufon create problems

The problem seems to originate from you selectors.

ul li a --> selects all 8 occurrences of <a>
ul li ul a --> selects only the 3 second-level occurrences of <a>

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

Cufon.replace('ul li a',{hover: true, fontWeight: 200});
Cufon.replace('ul li ul a',{hover: true, fontWeight: 700});

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

Cufon.replace('ul li ul a',{hover: true, fontWeight: 700});
Cufon.replace('ul li a',{hover: true, fontWeight: 200});

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

Cufon.replace('ul li a', { hover: true, fontWeight: 200 } );

and

Cufon.replace('ul li a', {
    hover: { fontWeight: 200 }
});

The first sets fontWeight to 200 and if the element is hovered also sets the fontWeight to 200, which would only be noticeable if the fontWeight 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文