View Full Version : Hi.. need help :P

01-28-2009, 09:28 PM
Javascript is doing my head in because I can't seem to do the simplest thing such as the size of my images.

My javascript generates random images but I would like to restrict the size of these images to e.g. 350x350pixels.

Would really appereciate any help.

Here is the JS code.

EDITSorry If I've posted this in the wrong section
Is there anyways I can make these random images fluid because my whole website is fluid and would like them to be fluid when I resize the browser.

function onloadMLR()
// sets Interval of how often the function will run
function animateMLR()
var images = new Array();
images[0] = 'images2/hats/hats-1.jpg';
images[1] = 'images2/hats/hats-2.jpg';
images[2] = 'images2/hats/hats-3.jpg';
images[3] = 'images2/hats/hats-4.jpg';
images[4] = 'images2/hats/hats-5.jpg';
images[5] = 'images2/hats/hats-6.jpg';
images[6] = 'images2/hats/hats-7.jpg';
images[7] = 'images2/hats/hats-8.jpg';
images[8] = 'images2/hats/hats-9.jpg';

var randomImageIndex = Math.floor(Math.random() * images.length);
document.getElementById('divMLR').innerHTML='<img src="' + images[randomImageIndex] + '" />'


01-29-2009, 04:47 AM
You can do this in either of these 2 simple ways:

1. You can set an inline style on your image tag Add highlighted:

<img src="' + images[randomImageIndex] + '" style="width:350px;height:350px;" />'

2. You can give the image an ID and style them with CSS.

Hope that helps.

01-29-2009, 09:45 AM
That worked thanks for help!!

Well I have one other problem mate, had this for a while and gave up on a solution. I hope you can help me else I'll have to settle for what I've got currently.

Basically, I have got a set of Links and whenever I click one of them and am on that respective page I would like an underline of its link to be a sort of page identifier, helping show the current page. I have got as far as being able to get the underline to work, but this is where I got stuck, the underline needs to be a different colour to the Links e.g. if links are black the underline of the current page link should be red.

01-29-2009, 09:51 AM
If the link is on your page you could give that special link it's own identifier:

<a href="#" id="unique">Link</a>

...then on your CSS, you could define that link using the set ID:

border-bottom:3px solid #f00;

This will display a 3px red border on the bottom of the link.

Hope it helps.