Context
Here is a jsfiddle that I've been working with: http://jsfiddle.net/21r7uvgx/
For context, I'm using http://malsup.com/jquery/cycle/basic.html to make the rotating banner cycle through each <a>
within the .custom-banners
wrapper. I have the script as an external resource within the jsfiddle.
Starting Point
The idea is to make each span
that has multiple lines (purely from window size) apply Style A, and those that have just one line apply Style B. Resizing the window changes what style each span
gets.
I'm doing it to the span
instead of the a
based on the assumption that to achieve what I want, I need to target a element that displays as a block by default.
Issue and Goal
The issue I'm running into is that with the cycling script, a span
that is not visible has a height of 0, so the math isn't right and it won't apply the correct style, even once the span
becomes visible.
The goal is to find a way to have it check a span
when it becomes visible, and apply the correct style.
Bonus Goal
If there's a better way to calculate the lineheight and determine what style needs to be applied, I'd also like those suggestions.
I was using this before, but it was very buggy when I manually resized the window.
var divheight = $(this).height();
var lineheight = $(this).css('line-height').replace("px","");
if (Math.round(divheight/parseInt(lineheight)) >= 2) {
$(this).attr('style','font-size: 10px');
} else {
$(this).attr('style','font-size: inherit');
};