www.webdeveloper.com
Results 1 to 13 of 13

Thread: Auto resizing image based on viewers screen resolution?

  1. #1
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28

    Question Auto resizing image based on viewers screen resolution?

    Making up a logo for my new site in gif format. It'll fill the top part of the screen in 800x600, but I want it to auto resize to fill screens on higher resolutions depending on the visitors res.

    Can this be done with JavaScript?

    Any help appreciated thanks.
    Nintendo Gamer writer

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Odds are, you image won't look all that great once it get's streached, but here's how:

    Code:
    <script type="text/javascript">
    function resizeImage() {
    	if (screen.width == 800) {
        	document.images["logo"].style.width = "800px";
    	}
    	else if (screen.width == 1024) {
        	document.images["logo"].style.width = "1024px";
    	}
    	/*You can add more here*/
    	else {
        	document.images["logo"].style.width = "1200px";
    	}
    }
    </script>
    
    </head>
    
    <body onload="resizeImage();">
    <img src="logo.gif" name="logo">

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28
    Thanks

    Originally posted by pyro
    [B]Odds are, you image won't look all that great once it get's streached,
    Well I'll actually be using a logo made for the highest res and shrinking it down for the smaller screens (assuming I can do that with this script?)

    Would there happen to be a script that will allow me to load a completely different sized version of the logo perchance? (for diffrent screen resolutions of course).
    Nintendo Gamer writer

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yes, that is actually the best way to do it. Try this:

    Code:
    <script type="text/javascript">
    function resizeImage() {
    	if (screen.width == 800) {
        	document.images["logo"].src = "yoursmall.gif";
    	}
    	else if (screen.width == 1024) {
        	document.images["logo"].src = yourmedium.gif";
    	}
    	/*You can add more here*/
    	else {
        	document.images["logo"].src = "yourlarge.gif";
    	}
    }
    </script>
    
    </head>
    
    <body onload="resizeImage();">
    <img src="logo.gif" name="logo">

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  5. #5
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28
    Thanks alot. I like these forums..
    Nintendo Gamer writer

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    You bet... Glad you do...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  7. #7
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28
    Hmm, I'm having trouble getting the different logo script to work. I've got it below with what I think I need to change, er, changed...


    Code:
    <script type="text/javascript">
    function resizeImage() {
    	if (screen.width == 800) {
        	document.images["logo"].src = "http://www.myserver.com/urnnlogo1.gif";
    	}
    	else if (screen.width == 1024) {
        	document.images["logo"].src = "http://www.myserver.com/urnnlogo2.gif";
    	}
    	/*You can add more here*/
    	else {
        	document.images["logo"].src = "http://www.myserver.com/urnnlogo3.gif";
    	}
    }
    </script>
    I'm assuming the above is correct? Not missing anything am I?

    I think I might be going wrong with the below code:

    Code:
    </head>
    
    <body onload="resizeImage();">
    <img src="logo.gif" name="logo"> [/B]
    What do I actually link the source too, seeing as I don't actually have a "Logo.gif", and do I need to keep the "name" command in there?
    Nintendo Gamer writer

  8. #8
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28
    Just wondering if anyone can help me out with the above problem please?
    Nintendo Gamer writer

  9. #9
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Make sure you point your image tag to an actual image. I would point it to the 800x600 one, as that is currently the most popular screen res. It is a good idea to do this anyway, as some 13% do not have javascript enabled...

    <img src="http://www.myserver.com/urnnlogo1.gif" name="logo">

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  10. #10
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28
    Will this script work off line, because I'm buggered if I can get it to work on my pc.
    Nintendo Gamer writer

  11. #11
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Yep, it works fine... Try this:

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  12. #12
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    28
    Ahh, I think I had some redundant code in there or something, I've got it working now, thanks.

    You're my own personal Jesus Christ..
    Nintendo Gamer writer

  13. #13
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Originally posted by GamerBlake
    You're my own personal Jesus Christ..
    I hope not...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09987 seconds
  • Memory Usage 2,983KB
  • Queries Executed 13 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (4)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (13)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (13)postbit
  • (13)postbit_onlinestatus
  • (13)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates