Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Cómo cambiar la familia de fuentes solo para un elemento - nextjs

Mi proyecto tiene una fuente global. pero solo para un elemento obtengo familias de fuentes al azar de una URL alojada. ejemplo:

 https://*****.com/file/fonts/Parnian.ttf

mi página es un CSR.

ahora ¿Cómo puedo usar esta fuente para mi elemento?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede cargar fuentes dinámicamente con Javascript.

 const fontFace = new FontFace(newFontName, `url(${newFontUrl})`); fontFace.load().then((loadedFace: FontFace) => { document.fonts.add(loadedFace); setFontFamily(newFontName); };

Aquí hay un ejemplo de carga dinámica de Google Fonts en NextJS.

ingrese la descripción de la imagen aquí

 import { useState } from 'react'; import type { NextPage } from 'next'; import * as font from 'random-google-font'; const Home: NextPage = () => { const [fontFamily, setFontFamily] = useState('cursive'); const updateFont = async () => { const response = await font.get(); if (response.length < 1) return; const newFontName = response[0].local[0].substring( 1, response[0].local[0].length - 1 ); const newFontUrl = response[0].url.ttf; const fontFace = new FontFace(newFontName, `url(${newFontUrl})`); const loadedFace = await fontFace.load(); document.fonts.add(loadedFace); setFontFamily(newFontName); }; return ( <div style={{ width: '100%', height: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '1em', }} > <span style={{ fontFamily }}>Hello S.M_Emamian!</span> <div style={{ cursor: 'pointer' }} onClick={updateFont}> 🔁 </div> </div> ); }; export default Home;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!