Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Help using jQuery to center an element horizontally and vertically over varying image dimensions. Re: Help using jQuery to center an element horizontally and vertically over varying image dimensions.

#79440
akeenlabs
Participant

It looks like the styling for the magnifier is based on a “span” tag but the span tag never gets created. In my tests, elem.append(“”) does not generate a span tag. Try this instead elem.append($(“<span />”)).

Also, your “a” tags will probably need the “position: relative” style for their absolutely positioned children (i.e., the new span) to display correctly.

Also, when calculating the left and top styles for the magnifier, you need to take into account the actual height and width of the magnifier. For example, left should be something like (this.outerWidth()/2)-(span.width()/2) and that value doesn’t need to be negative.

Warning: I haven’t tested this all the way, so I hope it helps.