how to dynamic control some picture's size by Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • blk.coffee@gmail.com

    how to dynamic control some picture's size by Javascript

    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="adjustS ize(this)" src="123.jpg">

    and write a function in javascript:
    function adjustSize(obj) {
    if (obj.width>250) {
    sizeRate=250/obj.width;
    obj.width=obj.w idth*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.

    can somebody tell me how to deal this.
    Tks advanced.

  • blk.coffee@gmail.com

    #2
    Re: how to dynamic control some picture's size by Javascript

    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.

    Comment

    • mouseit101@gmail.com

      #3
      Re: how to dynamic control some picture's size by Javascript

      You could move the onLoad to the body tag, does that work?

      Comment

      • Jeff North

        #4
        Re: how to dynamic control some picture's size by Javascript

        On 14 Feb 2006 16:51:16 -0800, in comp.lang.javas cript
        blk.coffee@gmai l.com
        <1139964676.364 213.144380@g47g 2000cwa.googleg roups.com> wrote:
        [color=blue]
        >| 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.[/color]

        There are 2 options.
        1. when storing the images to the database get the image dimension and
        save them also.

        2. since you are using server-side scripting you could use:
        eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 

        ---------------------------------------------------------------
        jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
        ---------------------------------------------------------------

        Comment

        • blk.coffee@gmail.com

          #5
          Re: how to dynamic control some picture's size by Javascript

          to mouseit101: TKS for your advice,but put that code in body tag got
          the same result.

          to Jeff: TKS a lot,you have been your wonderful help.
          i would choose the second way,since i had uploaded so many pictures to
          my webspace.
          Thanks for your wonderful code, it help me.

          Comment

          • Jeff North

            #6
            Re: how to dynamic control some picture's size by Javascript

            On 14 Feb 2006 18:49:18 -0800, in comp.lang.javas cript
            blk.coffee@gmai l.com
            <1139971758.192 889.242830@g14g 2000cwa.googleg roups.com> wrote:
            [color=blue]
            >| to mouseit101: TKS for your advice,but put that code in body tag got
            >| the same result.
            >|
            >| to Jeff: TKS a lot,you have been your wonderful help.
            >| i would choose the second way,since i had uploaded so many pictures to
            >| my webspace.
            >| Thanks for your wonderful code, it help me.[/color]

            No probs but I must point out that I'm not the author of the code :-)
            ---------------------------------------------------------------
            jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
            ---------------------------------------------------------------

            Comment

            Working...