So here’s my problem. I have Cufon font replacement which works fine. When the page loads, Cufon works as expected:
Cufon.replace('a.prettyFont', { fontFamily: 'First Font', hover: true });
All links with the prettyFont class are replaced, with hover functionality enabled. The problem comes when I replace the Cufon font after page load using this code:
$.getScript('newfont.js', function() {
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: true });
Cufon.refresh();
});
The new font shows up, but when I hover over any of the Cufon elements, it changes back to the old font. It seems that the hover option binds to the mouseover or mouseenter event to switch to the hover version of the original font, but it doesn’t change when you change the font. I was able to work around it using jQuery clone (cycle through each element Cufon replaced, swap out all HTML inside each element for just the text(), and then use jQuery replaceWith() to swap each item for its clone(). But that seems a little roundabout.
Is there an easier or more efficient way?
I am not sure, but try using jquery’s live() function. There are always issues with this cufon font dynamic replacement methods, hope this will be of little help.
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });
revaxarts said
TryCufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });
That’s the same as the code I’m using…it replaces the font, but the hover state is still the old font.
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
fillerspace said
revaxarts saidThat’s the same as the code I’m using…it replaces the font, but the hover state is still the old font.
TryCufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });
Did you noticed the apostrophe around true ?
revaxarts said
fillerspace saidDid you noticed the apostrophe around
revaxarts saidThat’s the same as the code I’m using…it replaces the font, but the hover state is still the old font.
TryCufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: 'true' });true?
Ah…I missed that. I tried it with the single quotes, and it is still the same. I guess I’ll have to stick with the jQuery clone hack:
$.getScript('newfont.js', function() {
$('a.prettyFont').each(function() {
$(this).html($(this).text());
var clone = $(this).clone();
$(this).replaceWith(clone);
});
Cufon.replace('a.prettyFont', { fontFamily: 'New Font', hover: true });
Cufon.refresh();
});
