最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to disable Cufon on certain elements? - Stack Overflow

programmeradmin3浏览0评论

I currently use Cufon accross our site with something similar to Cufon.set('fontFamily', 'DIN Medium').replace('h1'); Now for a single H1 tag i would like Cufon to be disabled, this is without changing the H1 tag to any other tag, it must remain as it is.

I can add classes etc to the H1 tag if required, and can do any HTML/CSS/JS just not changing the actual tag.

Anyone know if this is possible and if it is how?

Thanks in advance,

Shadi

I currently use Cufon accross our site with something similar to Cufon.set('fontFamily', 'DIN Medium').replace('h1'); Now for a single H1 tag i would like Cufon to be disabled, this is without changing the H1 tag to any other tag, it must remain as it is.

I can add classes etc to the H1 tag if required, and can do any HTML/CSS/JS just not changing the actual tag.

Anyone know if this is possible and if it is how?

Thanks in advance,

Shadi

Share Improve this question asked Apr 29, 2010 at 14:50 Shadi AlmosriShadi Almosri 12k16 gold badges60 silver badges80 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 11

Depending on which selector engine you use, you can:

  • add a class to your exception h1 element
  • you can use the :not selector to only apply cufon to the h1's that don't have the aforementioned class (with jQuery and classname 'clean' it would be something like Cufon.replace('h1:not(.clean)');
function remove_cufon(selector) {
    $(selector).html( cufon_text(selector) );
    return true;
}

function cufon_text(selector) {
    var g = '';
    $(selector +' cufon cufontext').each(function() {
        g = g + $(this).html();
    }); 
    return $.trim(g);
}

Usage:

remove_cufon('#name');

Using jQuery: Use the css class to h1 and specify in the selector...

$('h1.noCufon').each(function(){
        var cufonText = '';
        $('cufontext',$(this)).each(function(){
            cufonText+=$(this).html();
        });
    if(cufonText!=''){
        $(this).html(cufonText);
    }
})

by single h1 you mean?

$('h1').each(function(){
    if($(this).siblings('h1').length)
        Cufon.set('fontFamily', 'DIN Medium').replace(this);
});
发布评论

评论列表(0)

  1. 暂无评论