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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.