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
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post

    jQuery get position of div then save it to a cookie.

    Hi guys, need some help here. I was getting help on the jQuery forum but the person who was working with me stopped replying, so I'm hoping one of you can help me. Here's what's happening. I have divs on a webpage that you can drag around the page on the iPhone/iPad (this is only meant for those devices). I want the position of the divs to be saved when the page is reloaded, by putting it into a cookie. So far, I am using these plugins..

    http://plugins.jquery.com/project/Cookie
    http://www.manifestinteractive.com/iphone/touch/

    to drag the boxes around and save it to a cookie. Now I just need the code that get's the position and saves it. I got some help with it, and have this script:

    Code:
    $(document).ready(function(){
          // does cookie exist?
          if ($.cookie('the_cookie1')) {
                var coordsOne = $.cookie('the_cookie1').split(',');
                $('#theBox').css({top:coordsOne[0],left:coordsOne[1]});
          }
       
          if ($.cookie('the_cookie2')) {
                 var coordsTwo = $.cookie('the_cookie2').split(',');
                $('#theBox2').css({top:coordsTwo[0],left:coordsTwo[1]});     
          }
    });

    Which gets the position of the boxes, and then saves it to a cookie. Now, I need to figure out how to have the boxes get record their position and set it as a cookie (does that make sense?). I was told to use this script:

    Code:
     $.cookie('the_cookie',$('#theBox').css('top')+','+$('#theBox').css('left'));
    And I was supposed to put it on the "drag stop event" of the boxes, but I don't think the boxes have a drag stop event, or at least one I can't find. So, here is my JS code for the draggable boxes, where I think the code above would go...

    http://jsbin.com/iraxe/edit
    http://jsbin.com/akogu3/edit

    Thank you for reading this, and any help is much appreciated.

  • #2
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post
    Any ideas?


  •  

    Posting Permissions

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