Results 1 to 2 of 2

Thread: jquery to change height of sprite image

  1. #1
    Join Date
    Feb 2011

    jquery to change height of sprite image

    Hi there, I am trying to do something with a sprite image, which is changing the height of it when an action button is clicked. The sprite image is 602x5485px. For clarity here's the link http://www.antobbo.webspace.virginme...t/rewind_1.htm and here's the image http://www.antobbo.webspace.virginme...ges/sprite.jpg
    and when the "Run sequence" button is clicked the height of the background image is supposed to change (each image is 602x399) so I need to add another 399px to move to the next one. The sequence will run till the last picture and then come back so that it gives a kind of movie animation (so in brief adding 399px till it reaches the last pic and then removing 399px till it gets to the first one).
    Here's the html page without the script:
    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    		<title>Antonio Borrillo Photography - Gloom</title>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    		<meta http-equiv="Content-Language" content="en">
    		<meta name="description" content="Digital photography">
    		<meta name="keywords" content="Photography,Digital Photography,Antonio Borrillo,Antonio Borrillo Photography,Gloom,Faith,Light">
    		<meta name="author" content="Antonio Borrillo">
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
            <link rel="stylesheet" type="text/css" href="stylesheets/containers.css">
            <link rel="stylesheet" type="text/css" href="stylesheets/styles.css">
            <link rel="stylesheet" type="text/css" href="stylesheets/sprite.css">
            <!--[if lt IE 7]>
    			<link rel="stylesheet" type="text/css" href="stylesheets/ie6_and_below.css">
    		<div class="outer_wrapper">
            	<div class="inner_wrap">
                	<div class="banner">
                    	<div class="heading_1">
                        	<h1>Antonio Borrillo Photography</h1>
                        </div><!-- END OF heading_1-->
                    </div><!-- END OF banner -->
                    <div class="navigation">
                    		<li><a href="home.htm">Home</a></li>
                            <li><a href="gallery.htm">Gallery</a></li>
                            <li><a href="portfolio.htm">Portfolio</a></li>
                            <li><a href="bio.htm">Bio</a></li>
                            <li><a href="contact.htm">Contact</a></li>
                    </div><!--navigation ENDS -->
                    <div class="clear"><!-- EMPTY DIV TO CLEAR THE FLOAT-->
                    </div><!-- END OF EMPTY DIV TO CLEAR THE FLOAT-->
    				<div class="page_heading">
                    </div><!-- END OF page_heading -->
                    <div class="boxes_wrapper">
                    	<div class="thumb_container">
                   		</div><!-- END OF thumb_container-->
                   	<input type = "button" value = "Run sequence" class = "run_sequence_button">
                    	<div class="footer">
                    		<p class="footer_paragraph">All photos and content © 2011 Antonio Borrillo. Please read the <a href="terms_and_conditions.htm">terms and conditions here.</a>
                  		</div> <!-- END OF footer -->
                	</div><!-- END OF boxes_wrapper -->
            	</div> <!-- END OF content_wrapper-->
            </div>	<!-- END OF outer_wrapper-->
    And here's the css just for the sprite image:
    @charset "utf-8";
    /* CSS Document */
    	background: url('../images/sprite.jpg') no-repeat;
    /* to test coordinates work fine */
    background-position: 0px -399px;	
    }  /*
    	background: url('../images/sprite_button.jpg') no-repeat;
    Ok let's get to the script now (which won't be an external file but within the html page, I separated it temporarily for the sake of clarity). What the script should do, I think, is to get the background image which is in the css, and change the css background position adding - as said - 399px. When it gets to the end, remove 399px till it gets to the first image.
    So in practice here are my last (believe me of many!) attempt:
    <script type="text/javascript">
    var image = $(".thumb_container").css("background-image");/* to get the image*/
    /* console.log(image);*/
    $("#" + image).css("backgroundPosition", "0px -399px"); /* this is to change the size of the image */
    I am not sure whether this is correct but I am not quite sure how to continue. The thing is, I want to change the height of the background image as said and the above should change at least one image but it doesnt work. If somebody has the patience to talk me through that (I am a beginner so I would like to attempt to build the code myself, so perhaps for now it might be better if you don't post the whole solution if you know what I mean but just an advice or maybe to put me onto the right track) I would really appreciate it

  2. #2
    Join Date
    Feb 2011
    Hi I think I made some small progress in that now it partially works. I have done some research, looked up other sites and things and I realized that the way I was doing it wasn't the right way. So my script now has changed and is simpler:

    <script type="text/javascript">
    var image_change = $(".thumb_container").css("backgroundPosition", "0px -399px");
    I was creating unnecessary variables, and I realized I don't need to get he height and width of the image, I can work on the width and height of the div containing the image
    So when I click on the RUn sequence button now the image actually change, now I have to find a way so that when the button is clicked the sequence runs all the way till the end and goes back to the first image.
    I suppose I need to have a variable that stores the x and y, say sth like
    var image_position_x = 0;
    var image_position_y	= 0;
    and then perhaps a while loop that increments the y value. But how do I increment just the y value in the jquery script?

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.16296 seconds
  • Memory Usage 2,864KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (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
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (2)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (2)postbit
  • (2)postbit_onlinestatus
  • (2)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
  • postbit_imicons
  • bbcode_parse_start
  • 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