Cufon - jQuery,点击时替换字体颜色

发布于 2024-08-16 06:40:50 字数 427 浏览 8 评论 0原文

我使用 cufon 进行一些字体替换,并使用 jQuery 构建自定义手风琴。

我的手风琴的代码是这样的:

 $(".acc-title").click(function () {
   //show something, hide something etc.
 });

在单击事件期间是否可以更改替换(使用 cufon)字体的颜色?

像这样的东西:

$(".acc-title").click(function () {
       //some something, hide something etc.
       Cufon.replace('how do i select ONLY the title of this', { color: '#fff' });
});

I am using cufon for some font replacement and jQuery to build a custom accordion.

the code for my accordion is something like this:

 $(".acc-title").click(function () {
   //show something, hide something etc.
 });

Is it possible during the click event to change the color of the replaced (with cufon) font?

something like:

$(".acc-title").click(function () {
       //some something, hide something etc.
       Cufon.replace('how do i select ONLY the title of this', { color: '#fff' });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

煮酒 2024-08-23 06:40:50

您必须使用 Cufon.refresh();通过CSS改变颜色后。像这样:

$("#tab1").click(function() {
   $("#tab2").removeClass("selected");
   $("#tab1").addClass("selected");
   Cufon.refresh();
}

You must use Cufon.refresh(); after you change the color by CSS. Like this:

$("#tab1").click(function() {
   $("#tab2").removeClass("selected");
   $("#tab1").addClass("selected");
   Cufon.refresh();
}
幼儿园老大 2024-08-23 06:40:50

我会考虑使用 CSS 类,而不是通过 css 函数更改颜色

$(document).ready(function(){
    $(".acc-title").click(function () {
        $("#cufonid").addClass('cufonCSSClass');
    });
});

尽管如此,如果您想要显示/隐藏:

        $("#cufonid").show();
        $("#cufonid").hide();

如果 acc-title 是您正在操作的内容,那么以下内容就足够了:

    $(".acc-title").click(function () {
        $(this).addClass('cufonCSSClass');
        //or
        $(this).hide();
        //etc, etc
    });

您也可以通过将上面的 acc-title 选择器与父元素的 ID 相结合来加速它。

    $("#somparentid .acc-title").click(function () {

或者给该项目一个ID itslef:

    $("#acc-title").click(function () {

或者,你的h2(不过,这有点慢):

    $("h2.acc-title").click(function () {

所以,总而言之,你的答案可能看起来像这样:

$(document).ready(function(){
    $("h2.acc-title").click(function () {
        $(this).addClass('cufonCSSClass');
    });
});

但我猜测了一下,因为我不完全确定你是什么正在追随

I would be looking at using a CSS class instead of changing the colour through the css function

$(document).ready(function(){
    $(".acc-title").click(function () {
        $("#cufonid").addClass('cufonCSSClass');
    });
});

Although, if you are looking to show/hide:

        $("#cufonid").show();
        $("#cufonid").hide();

If acc-title is the thing you are operating on, then the following will suffice:

    $(".acc-title").click(function () {
        $(this).addClass('cufonCSSClass');
        //or
        $(this).hide();
        //etc, etc
    });

You could also speed the above acc-title selector by combining it with the ID of a parent element.

    $("#somparentid .acc-title").click(function () {

Or give the item an ID itslef:

    $("#acc-title").click(function () {

Or, your h2 (this is a little slower, though):

    $("h2.acc-title").click(function () {

So, to summarise, your answer might look something like:

$(document).ready(function(){
    $("h2.acc-title").click(function () {
        $(this).addClass('cufonCSSClass');
    });
});

But I'm guessing a bit as I'm not entirely sure what you're after

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