Results 1 to 4 of 4

Thread: Auto resize image according to dhtmlwindow Size

  1. #1
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Auto resize image according to dhtmlwindow Size

    1) Script Title: DHTML Window widget (v1.1)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

    3) Describe problem:

    I'm wanting to have an Image auto resize according to the size of the popup ajax widget, ie if a person resizes the window the image adjusts accordingly


    I have tried

    Code:
    <script type="text/javascript">
    
    function resizeImage()
    {
    var window_height = document.body.clientHeight
    var window_width = document.body.clientWidth
    var image_width = document.images[0].width
    var image_height = document.images[0].height
    var height_ratio = image_height / window_height
    var width_ratio = image_width / window_width
    if (height_ratio > width_ratio)
    {
    document.images[0].style.width = "auto"
    document.images[0].style.height = "100%"
    }
    else
    {
    document.images[0].style.width = "100%"
    document.images[0].style.height = "auto"
    }
    }
    </script>
    
    <body onresize="resizeImage()">
    <center><img onload="resizeImage()" margin="0" border="0" src="MyImage.jpg"></center>
    </body>

    Any ideas if this is possible ?

  2. #2
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry to bump this post, But has anyone got an idea on how i can get an image to resize itself automatically based on the size of the window...

    ie if a person drags the window bigger the image resizes accordingly ?

  3. #3
    Join Date
    Feb 2009
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Part of the issue may be what type of dhtmlwindow you have. I am using inline windows and iframe windows. I believe that my solution may work for all types. What I do is create a onresize event similar to the onclose event so that you can put in a custom event handler.

    First, in the source: add the following line in red after the t.onclose definition:

    t.onclose=function(){return true} //custom event handler "onclose"
    t.onresize=function(){}

    Then, add a call to the function in both the setSize function and the resize function:

    setSize:function(t, w, h){ //set window size (min is 150px wide by 100px tall)
    t.style.width=Math.max(parseInt(w), 150)+"px"
    t.contentarea.style.height=Math.max(parseInt(h), 100)+"px"
    t.onresize();
    },

    resize:function(t, e){
    t.style.width=Math.max(...
    t.contentarea.style.height=Math.max(...
    t.onresize();
    },

    Now you can override the default (null) function in your javascript:

    mywindow.onresize=function(){.. resize your image or whatever ..}

    I believe that this approach will work for any type of dhtmlwindow or dhtmlmodal.

  4. #4
    Join Date
    Nov 2008
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks i'll give that a try

Bookmarks

Posting Permissions

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