Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Member #
    30082
    I want to dynamically set the height and width of an image using javascript so that the image looks proportionally fine according to different screen resolutions..

    The original image is of 252*62 pixels..

    I have used the following code..but it doesnt seem to work.
    Code:
    <script type="text/javascript">
    function resizeheight() {
        var height = ((62*screen.height)/800);
    
        return height;
    }
    function resizewidth() {
        var width = ((252*screen.width)/1280);
    
        return width;
    }
    HTML Code:
    <img id="enter" src="enter.PNG" height="resizeheight()" width="resizewidth()" >


  2.  

  3. #2
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Member #
    30082
    I got to know that we can't embed javascript calls like for the height and width attributes of an image.

    Used another method. It worked.

    Code:
    <img id="enter" src="enter.PNG" alt="enter" />
    
    <script type="text/javascript">
    target=document.getElementById('enter');
    target.style.width=((252*screen.width)/1280)+'px';
    target.style.height=((62*screen.height)/800)+'px';
    </script>


Remove Ads

Posting Permissions

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

Search tags for this page

dynamic adjust img width

,

dynamically set image width & height

,

how to set the style and src of an image dynamically using javascript

,

img js set width

,

info height image with javascript

,

javascript set image height depending on another image

,

parse image width and height javascript

,

set image on image control using javascript

,

set the style width dynamically in html using javascript

,

set width and height of image in javascript

Click on a term to search for related topics.
All times are GMT -6. The time now is 06:51 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com