Click to See Complete Forum and Search --> : Preferred method of positioning an image?
Knutars
11-14-2008, 07:42 PM
I want to position an image (128 x 128 px) randomly along a horizontal line limited by the width of a table (1000 px) at each page load. What method is the easiest for this task; php, javascript or something else?
The site is built in php/mysql, and I already use php to fetch a random image from within a folder (by Dan P. Benjamin, Automatic, Ltd).
slaughters
11-19-2008, 05:00 PM
Do something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PositionImage Test</title>
<script>
function PositionImage() {
var imageObj = document.getElementById('anImage');
imageOb.style.position = 'absolute';
imageOb.style.top = '100px'; // Use some random number here
imageOb.style.left = '40px'; // Use some random number here
}
</script>
</head>
<body onload="PositionImage();">
<img id='anImage' src='Knutars.jpg'>
</body>
</html>
infinityspiral
12-04-2008, 10:06 AM
The above works great unless javascript is turned off, in which case php would be the most compatible method because it would generate a page on the fly that the user doesn't have to process. Most people don't have javascript turned off though so you're not losing out on a big audience if you go the javascript route.