Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts

    Horizontal Sliding div only works in Firefox

    www.vicesbyproxy.com/staging/justrich/

    I have a #thumbs div that moves back and forth incrementally inside of a #maincontent div, filling it entirely. It slid back and forth fine when you clicked the arrow, but it would slide completely off the screen if you kept clicking. I added some code to limit how far it could slide in either direction.

    The code works fine in Firefox, doesn't work at all in Safari or on the iPad. Here is what I did:

    Code:
    <script type="text/javascript">
    	$(function() {
    		//animate move to left 
    		$("#moveAhead").click(function() {
    			//get width of thumbs minus width of maincontent
    			var t = parseInt($("#thumbs").css("width")) * -1;
    			var m = parseInt($("#maincontent").css("width"));
    			var s = t + m;
    			
    			if (parseInt($("#thumbs").css("left")) > s) {
    				$("#thumbs").animate({left: "+=-25%"}, 500, "swing");
    			}
    		});
    		//animate move to right (x axis) if the div's left position is less than 0
    		$("#moveBack").click(function() {
    			if(parseInt($("#thumbs").css("left")) < 0) {
    				$("#thumbs").animate({left: "+=25%"}, 500, "swing");
    			}
    		});
    	});
    </script>
    Last edited by marilynn.fowler; 07-10-2013 at 10:01 AM.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    Well, I figured it out. I changed the if line to be the following:
    Code:
    if($("#thumbs").position().left > s)
    Now it works.
    Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. Groucho Marx


  •  

    Posting Permissions

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