Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hi.. need help :P

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


    Code:
    function onloadMLR()
    {
    // sets Interval of how often the function will run
    window.setInterval("animateMLR()",1500);
    }
    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] + '" />'
    
    }
    Last edited by Farah; 01-28-2009 at 09:57 PM.

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    You can do this in either of these 2 simple ways:

    1. You can set an inline style on your image tag Add highlighted:
    Code:
    <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.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    If the link is on your page you could give that special link it's own identifier:
    Code:
    <a href="#" id="unique">Link</a>

    ...then on your CSS, you could define that link using the set ID:
    Code:
    #unique{
    text-decoration:none;
    border-bottom:3px solid #f00;
    }
    This will display a 3px red border on the bottom of the link.

    Hope it helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •