Excluding some tags from the Cufon Font system

I use Cufon to download some good fonts using javascript. And, since I have many tags, I use the following command to replace all tags:

Cufon.replace('*', { fontFamily: 'MyFont' }); 

But I recently decided to exclude some tag classes from substitution. Is there an instruction like:

 Cufon.exclude('TheClassToExclude'); 

?

+4
source share
2 answers

Using * as a selector is a pretty bad idea. For example, it takes forever to load the page and run the script, since Cufon blocks the browser while it draws. Secondly, your text will not be displayed depending on the browser. (At this time, FF3.6 does not display Cufon text selection)

But to answer your question, you can point cufon to specific classes, just add classes to the elements you want to draw Cufon, and not vice versa.

Cufon.replace('h2.cufon', { fontFamily: 'MyFont' });

Edit:

Just found that if you use a Javascript library like jQuery, you can use a different selector to exclude elements.

Cufon.replace('h2:not(.nocufon)', { fontFamily: 'MyFont' });

This will replace all H2 elements with Cufon text, except those that have the nocufon class.

+15
source

You can use '> to select the exact element / element class if necessary. I use this method on the drupal website to select all level 2 sidebars,

'# sidebar-left.menu-level-2> ul.menu> li> a'

0
source

Source: https://habr.com/ru/post/1303535/


All Articles