I think you can recreate the element that makes up the name of the song, and get its width in pixels. If your width is larger than the width of your container, you can resolve to create a <marquee>
.
To apply the recreation of the element simply remove one of the .som
and then pull the new element into the same container.
Obs.: The span width is being broken by the container itself, preventing comparison of its width with that of its container. Some style would solve this.
Remember that you do not need to re-create the Marquee/span element.
Example of how to pre-store Marquee/span:
var span = document.createElement('span');
span.className = 'som';
/* Desaplica a largura fixa de 300px: */
span.width = 'auto';
var marquee = document.createElement('marquee');
marquee.className = 'som';
Example of how to update the song name:
/* Remove o marquee por precaução: */
marquee.remove();
var nomeDaMúsica = 'Nome da música';
var container = document.querySelector(
'.player .caixa-status'
);
span.textContent = nomeDaMúsica;
// Para obter a largura renderizada do span vai ser necessário
// adicioná-lo ao container (obs.: se ele já estiver adicionado
// ele não duplica, de acordo com meu navegador):
container.appendChild(span);
var largura = som.offsetWidth;
if (largura > container.offWidth) {
/* Transforma o elemento span em marquee: */
span.remove();
marquee.textContent = nomeDaMúsica;
container.appendChild(marquee);
}
you are to use bootstrap or you are doing everything by hand ?
– PululuK
I’m doing the hand, with bootstrap is possible?
– Paulo Sérgio Filho
Possible duplicate of Font Responsiva
– Guilherme Nascimento
Obs.: the site is pretty cool.
– viana
Have you ever thought of cutting the text, including "..." at the end and adding the full name to the title property, is it usually done like this? I do not think it is possible in a simple way to adjust the font size according to the available space. But even if it is possible, I do not think it will look so good. It will seem that your site does not follow a pattern.
– mau humor
Are you talking about text-overflow: Ellipsis? I need the song name to be complete.
– Paulo Sérgio Filho
Do you want the text size to decrease if its number of characters is wide? Or cut as told by @mauhumor?
– Klaider
.player . status box . sound { font-family:Segoe UI Bold; font-size:40px; color:#FFFFFF; width:300px; text-Transform:uppercase; text-shadow: 0px 2px 0px rgba(0,0,0,0.2); }
– Paulo Sérgio Filho
@Paulosérgiofilho My internet was slow, I think I know what you’re talking about.
– Klaider
You could try to change the font px, by in or %. But this would only have effect if the screen size changes. I believe.
– mau humor
@Paulosérgiofilho I just left an answer, you can analyze and adapt in your project !
– PululuK
What you need is something like "overflow:resize-text;". But that doesn’t exist. Maybe you have to calculate in Javascript. As already answered (I have not tested).
– mau humor
Maybe this is it: http://stackoverflow.com/questions/13358181/resize-font-size-according-to-div-size
– mau humor
Doesn’t look like a duplicate of the one indicated at the closing. The indicated does not resolve what was requested, which is to adjust the font size according to the variable text size, to fit.
– Bacco
Use Font Awesome, it is with Bootstrap, will save you time and they have various functions.
– Diéfani Favareto Piovezan