To see the issue:
Create a horizontal carousel inside a display: none container.
Make sure it has zero margins if you want to see the issue in browsers
other than Safari.
Don't worry about the zero margins in Safari, it'll break anyway.

The pos method will check the dimensions of the elements in the line
var d = this.dimension(e);

Unfortunately, if the parent container is set display:none, the
dimension method's reliance on offsetWidth when calculating old will
cause it to report back zero width for the elements. They may well
have a CSS width property, they may have padding... but offsetWidth
can't see it as it returns zero on hidden elements.

Once d is zero, we get the error message:
"jCarousel: No width/height set for items. This will cause an infinite
loop. Aborting..."

dimension also checks the margins. You can somewhat dodge this problem
(though it's hardly ideal) by giving your carousel items a left or
right margin of one or greater. As it adds the margins to the zero
offsetWidth, you get a non zero value and pos doesn't bail on you.

The challenge is, even this doesn't fully fix it as dimension uses the
$jc.margin method. $jc.margin returns the $(el).css('margin-right')
for right margins just fine for everything *except* Safari. For
Safari, it does a separate trick, calculating margins based on the
difference between two offsetWidth values. As the element's hidden,
they're both zero. Difference between zero and zero is zero, it
returns zero for the right margin on hidden elements in Safari.

So, with zero margins being reported, along with zero width, Safari
*always* throws the alert when you run pos on a currently hidden
carousel - while other browsers only throw the alert when the margins
are also zero.

It's kind of a deep one to even find - you have to be doing something
with the carousel that triggers pos (i.e. initializing) while it's
inside a hidden container. Plus, if you have margins, you'll never see
it in anything other than Safari. Still, when it does come up, it's a
major pain to figure out what it's doing and work around.

I hope all of that made sense. Like I said, it's kind of buried.

Reply via email to