How to disable Cufon on certain elements?

后端 未结 4 743
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-30 10:53

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

相关标签:
4条回答
  • 2020-12-30 11:05

    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);
        }
    })
    
    0 讨论(0)
  • 2020-12-30 11:06
    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');
    
    0 讨论(0)
  • 2020-12-30 11:14

    by single h1 you mean?

    $('h1').each(function(){
        if($(this).siblings('h1').length)
            Cufon.set('fontFamily', 'DIN Medium').replace(this);
    });
    
    0 讨论(0)
  • 2020-12-30 11:24

    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)');
    0 讨论(0)
提交回复
热议问题