Jump to content

javascript formula for a left margin


The Little Guy

Recommended Posts

If you take a look at this page using firefox, then chrome/safari:

http://www.dudeel.com/home.php?id=2

 

When you mouse over the images in the "Photo Gallery" section, you should notice that firefox enlarges the images correctly, but chrome/safari doesn't.

 

 

if((verOffset=browser.indexOf("Chrome"))!=-1 || (browser.indexOf("Safari")) != -1){
mLeft = -(width / 2)+"px";
}else{
mLeft = -(width / 2)+"px";
}
img.setAttribute("style", "position:absolute;margin-top:"+mTop+";margin-left:"+mLeft+";");

 

The above is basically what I use, inside the first if statement, is the code for "Chrome" and "Safari" The bottom is for everything else (haven't tested on much yet). After the if statement, it sets the style of the image, and the left margin doesn't display correctly in Chrome/Safari.

 

Anyways, any ideas how to make the image enlarge correctly in chrome/safari? I can't find a good formula to handle this in chrome/safari.

Link to comment
https://forums.phpfreaks.com/topic/169133-javascript-formula-for-a-left-margin/
Share on other sites

I can't say for sure - usually I just play with these things until I find something that works. But maybe try this for Chrome/Safari

 

mLeft = "-" + (width / 2) +"px";

 

If it works, it actually may work for other browsers as well, removing the need for the conditional.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.