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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to use js to adject pic sizes dynamicly after loading.?

    i have some pictures in a page. there are have difference sizes. some
    of them are too widen for be arrange in a line. so
    i been tried to adject their sizes to more suitable.

    i add a event to that image likes:
    <img id="img" onLoad="adjustSize(this)" src="123.jpg">


    and write a function in javascript:
    function adjustSize(obj){
    if (obj.width>250){
    sizeRate=250/obj.width;
    obj.width=obj.width*sizeRate;
    if (obj.hight>268)
    obj.hight=268;
    }


    }


    but exactly,i can get the image's width and height. cuz the loading
    hasn't finished while the function of adjustSize works.

    In addition,those picture were loaded from a database.
    so first i can't exactly get the sizse when a bigger picture is
    loading.
    thus in the event of picture loading the function isn't works cuz it
    keeping a wrong sizes as zero.
    but the event 'onMouseOver' works well.cuz it cant get the size exactly
    after they were completely loaded


    can anyone tell me how to deal this?
    Tks advanced.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    have u tried using offsetHeight and offsetWidth attributes of the image

  • #3
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try using CSS to resize your pics. Although they all may have to be sized to the same dimension. Take a look at the end of this page...

    http://www.vladdy.net/Demos/ElementSizing.html

    stymie


  •  

    Posting Permissions

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