Results 1 to 4 of 4

Thread: Jquery stop "animate left" on div bounds

  1. #1
    Join Date
    Apr 2010

    Jquery stop "animate left" on div bounds

    Hi all sorry if this is in the wrong section, let me know and i'll move it. I am new to javascript and indeed jquery but I have muddled a page together here but want to stop the left and right links at the bottom animating over my "contents" div's bounds so it doesn't slide past the edges of my div either way. Can i do this or am i barking up the wrong tree? Hopefully you will understand, I don't know if i am explaining myself correctly, but if you have a look at the page and press "Right" twice you will see what i mean, I don't want it to go any further than the end (red) or indeed further past than the start (green). Thanks for taking the time to read this.

    My Code:
    	position: relative;
    	top: 0;
    	left: 0;
    	width: 786px;
    	height: auto;
    #scrollable{ overflow: hidden; width: 786px; height: 500px; border: 1px
    solid black;}
    <script type="text/javascript" src="Scripts/jquery.js"></script> 
    <script type="text/javascript"> 
    		$("#contents").animate({left: "+=786"}, 1200)
    		return false;
    		$("#contents").animate({left: "-=786"}, 1200)
    		return false;
       <div id="scrollable"> 
       <div id="contents"> 
    <table width="1572" border="0" cellspacing="0" cellpadding="5"> 
        <td width="776" valign="top" bgcolor="#00FF00"><p>Lorem ipsum dolor sit amet, elit tempor convallis, viverra cursus pede iaculis bibendum suspendisse turpis. Erat morbi imperdiet nisl. Blandit augue ac eget, ut nascetur. Faucibus non auctor iaculis quis luctus quam, maecenas non nunc, justo in placerat. Mus sem dui consequat at, vel ad mollis porta nibh tempus quis, per quis. At urna, felis id lorem molestie dignissim libero, velit aliqua ut nec venenatis sed. Suspendisse iaculis lectus tincidunt consequat viverra mattis, odio mattis quis molestie erat ultricies, eget ac eu erat mi, ut mauris in vehicula commodo vestibulum. Pellentesque vitae placerat inceptos sit, accumsan sodales amet et fames aliquam. Placerat duis vestibulum a montes ut orci, feugiat porta neque auctor dui. Accumsan ut ratione, sed massa integer a enim, felis parturient. Tincidunt sed et lobortis, viverra cursus, velit duis ac libero in, suscipit ultrices, sit et quam sit sit dolor.</p> 
          <p>Vel sed quam, elit viverra libero non ut, sagittis semper ultrices maecenas, augue etiam justo eget, sed luctus non odio ut. Laoreet feugiat tincidunt fames curabitur, venenatis vitae, aliquet pede ut amet nonummy nascetur ut, vitae id nunc phasellus sed. Nisl molestie pulvinar semper, nascetur interdum diam a qui. Lectus odio luctus posuere lobortis, nunc nec egestas mattis nunc congue elit. Non dis arcu ac blandit, duis vitae quis turpis, urna dolor non nullam praesent elit quis, vel nullam vitae pulvinar habitasse fusce, sed pellentesque. Nulla nullam qui lacus accumsan consectetuer, ante sit massa ut mauris laoreet.<br /> 
        <td width="776" valign="top" bgcolor="#FF0000"><p>Lorem ipsum dolor sit amet, et nunc arcu, pede non, eget faucibus pretium ut eget gravida odio. Varius molestie sociosqu purus semper, ac nulla eget per, veniam condimentum volutpat quis, sit auctor cras vitae diam quis elementum, nonummy risus varius dui quis dictum dolor. Pellentesque eu turpis, aliquam at duis. Vitae augue praesent mauris sociis est proin, wisi nam convallis et nec vel ligula, mollis arcu metus vel lacus. Nec ultricies neque praesent cubilia vestibulum scelerisque, sed sit dictumst *** viverra, luctus aut elit parturient. Vestibulum vehicula enim, ultricies lectus turpis lobortis, pellentesque wisi tincidunt interdum vestibulum, convallis erat maecenas suspendisse. Cursus volutpat, sollicitudin lorem, wisi vel consequat eu eros non, libero eros bibendum, magna lacinia sed cras massa posuere. Convallis mi ligula et dictumst, aenean mauris sed eget wisi dapibus viverra, magna enim quis, lacus sodales. Amet ultrices blandit sapien, integer mauris vitae, diam quis non massa dolor consequat.</p> 
          <p>Proin pellentesque at, cursus ac, maecenas dignissim sed enim nec omnis, libero urna nibh ac. Nec eget consectetuer proin sapien eget id, vel consequat integer cras euismod nonummy mattis. Adipiscing sapien justo, sodales vitae nec natoque nulla. Arcu rutrum tellus nulla ultrices nec tincidunt, bibendum eu ipsum eu, tortor eros sed auctor orci aliquet pellentesque. Fusce tortor vel in eu, ut sed curabitur odio nunc, vivamus sed in cursus tempor nonummy.</p> 
          <p>Rhoncus vel litora vitae posuere urna, curabitur sodales, sit elit phasellus. Cras arcu suspendisse pede curabitur rhoncus, taciti nec vulputate diam mauris. Quis non sollicitudin curabitur, eros amet risus mollis. Vitae semper per, nulla mi, molestie elit pellentesque integer et vel pellentesque, rutrum ante gravida. Elit tincidunt non vestibulum, quam nisl proin. Erat ut, eleifend pharetra ullamcorper, sed turpis pellentesque elementum, orci amet orci lectus donec, risus dis.</p> 
          <p>Fusce purus facilisis, euismod risus volutpat sed wisi, pulvinar sed lectus tincidunt suscipit. Mauris euismod non vel nisl nunc pellentesque, molestie feugiat, proin eget tincidunt aliquam, facilisis sociis erat, inceptos dui. Fusce in aliquam urna ante vel, amet est turpis lacus. Quam ac. Wisi reprehenderit sapien sit libero eu, sed dictum fusce eget mauris duis arcu. Amet quis curabitur faucibus leo, id sit placerat nam orci vivamus parturient, eu non qui quis ligula, et id proin vulputate commodo, massa eget cursus. Lorem urna dictum, nam aliquet lacinia diam, elementum nibh et enim tortor turpis placerat, aliquet interdum orci nunc sodales eget platea, donec lectus eu fermentum eget nunc.<br /> 
    <a href="#" class="leftpush">Left</a>  <a href="#" class="rightpush">Right</a> 

  2. #2
    Join Date
    Sep 2009
    Hey dutchboy, it wouldn't take much to stop it from going past. Something as simple as a "keep track" variable which stops the animation from happening if() left is > then...

    but there is no point in re-creating the scroller wheel.

    I have been using that plug-in for a while, great control and additional plug-ins for it (Circular)


  3. #3
    Join Date
    Jan 2003
    You can solve this by precalculating what the result will be and comparing it to a specified limitation. Try this for your right link's function.

    var distance = 786;
    if(Math.abs(parseInt($("#contents").css("left"),10))+distance >= ($("#contents").width() * $("#contents table td").length)){
        distance = 0;
           left: "-=" + distance + "px"
     }, 1200);
    return false;
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  4. #4
    Join Date
    Apr 2010
    Wow thanks to both of you, very helpful

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