Results 1 to 6 of 6

Thread: Sticky Div

  1. #1
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Red face Sticky Div

    I am trying to produce a sticky side menu for a page on my website ( http://familyfostering.ismywebsite.co.uk/fosterwith.php ) and using a tutorial from this site http://www.wduffy.co.uk/blog/keep-el...-using-jquery/

    It has worked perfectly, however I need it to stop scrolling at a certain point so you can get to the bottom page, you will see what I mean on the page. Any suggestions?

    JS
    Code:
    $().ready(function() {
    		var $scrollingDiv = $("#sticker");
     
    		$(window).scroll(function(){			
    			$scrollingDiv
    				.stop()
    				.animate({"marginTop": ($(window).scrollTop() + 0) + "px"}, "fast" );			
    		});
    	});

    CSS

    Code:
    #sticker {
    	width:210px;
    	height:auto;
    	display:block;
    	float:left;
    	overflow:hidden;
    }

    HTML

    HTML Code:
    <head>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    <script type='text/javascript' src='js/js.js'></script>
    </head>
    
    <div id="main">
    
    <div id="sticker">
    <ul id="sidemenu">
    <li><a href="#">Page</a></li>
    <li><a href="#">Page</a></li>
    <li><a href="#">Page</a></li>
    <li><a href="#">Page</a></li>
    <li><a href="#">Page</a></li>
    </ul>
    </div>
    
    <!--Content-->
    
    </div> <!--wanting the sticky div to stop at this point-->

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    quick fix

    Code:
    $().ready(function() {
    		var $scrollingDiv = $("#sticker");
    		$(window).scroll(function(){
    			$scrollingDiv
    				.stop()
    				.animate({"marginTop": Math.min(($(window).scrollTop() + 0),2400) + "px"}, "fast" );
    		});
    	});
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    gemzilla (09-02-2014)

  4. #3
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Damn you beat me to it
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  5. #4
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    Thank you Lol.. Is it possible to not have a fixed position?

  6. #5
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    What I mean is I'm trying to get the scroll effect on a couple of pages, but with the fixed position it stops miles up the page on other pages.

  7. #6
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    with this variable top is the initial top margin of the stickey

    Code:
    $().ready(function() {
    		var $scrollingDiv = $("#sticker");
            var top=100;
     			$scrollingDiv
    				.stop()
    				.animate({"marginTop": top + "px"}, "fast" );
    	$(window).scroll(function(){
    			$scrollingDiv
    				.stop()
    				.animate({"marginTop": Math.min(($(window).scrollTop() + top),2400) + "px"}, "fast" );
    		});
    	});
    if this is not what you want please explaine further or provide an example
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  8. The Following User Says Thank You to vwphillips For This Useful Post:

    gemzilla (09-25-2014)

Similar Threads

  1. DD Sticky bar
    By IrishPidge in forum Dynamic Drive scripts help
    Replies: 10
    Last Post: 05-14-2013, 12:56 PM
  2. Sticky bar issue
    By mediaslave in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-17-2012, 04:49 PM
  3. Sticky Tooltip script - not sticky
    By jscheuer1 in forum Bug reports
    Replies: 0
    Last Post: 11-09-2010, 03:01 PM
  4. Sticky Note - Please Help =)
    By Seannal in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 05-27-2007, 06:14 PM
  5. CSS Sticky Footer (CSS/JS)
    By wyclef in forum CSS
    Replies: 0
    Last Post: 12-13-2006, 03:52 PM

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
  •