Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5993137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:37:55+00:00 2026-05-22T23:37:55+00:00

hey guys, I can’t seem to get it working. I have draggable black bars

  • 0

hey guys,
I can’t seem to get it working. I have draggable black bars that act as navigation on top of the content.

I simply want to browser to remember the position of the bars with a cookie. Whenever a user drags the bars and clicks something else (the page refreshes) the bars should stay at the last position.

I can’t seem to get it working. Moreover I wish to have a simple random distribution of the bars when a user visits the site for the first time.

I’ve built a quick example. Maybe you know what I’m doing wrong here: http://jsfiddle.net/RZQ8H/

$("ul.bars li").draggable({
     stop: function(event, ui) {
         var currentPos = $(this).position();
         var currentTop = Math.round(currentPos.top);

         // save cookie when stopped dragging
         $.cookie('position' + $(this).index('li').toString(), currentTop.toString());
     }
});

The position when the page is loaded…

// initial position of elements
$("ul.bars li").each(function() {

        // if no cookie is set (first visit to page) all bars should be distributed
        // randomly across the document

        if ( $.cookie('position'+ $(this).index('li').toString()) ) {
            var doc = $(document).height() - 50;

            // random distribution of elements
            $("ul.bars li").each(function() {
                var randPos = Math.random(0)*doc;
                $(this).css('top' , randPos+'px');
            });

        } else { 

            // if a cookie exists (the bars have already been dragged)
            // remember the position

            var savedPos = $.cookie('position' + $(this).index('li').toString());            

            $(this).css({ top: savedPos + 'px' });
        }

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:37:56+00:00Added an answer on May 22, 2026 at 11:37 pm

    You got your condition wrong way around:

    if ($.cookie('position'+ $(this).index('li').toString()) ) {
    
                // random distribution of elements
    
    
            } else {
    
                // if a cookie exists (the bars have already been dragged)
                // remember the position
    
            }
    

    Swap it around, so that if a cookie exists, it won’t randomly distribute them.

       if (!$.cookie('position'+ $(this).index('li').toString()) ) {
    

    Example:
    http://fiddle.jshell.net/RZQ8H/3/show/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, i can't seem to get it working. i have a div.post with
Hey guys I have an older site that is coded in AS2(I can't get
Hey guys, I have this quick bit of code that I can't figure out
Hey guys, I have a bit of a problem that I can't solve. I'm
Hey guys I can't seem to get the syntax here right, I'm just trying
hey guys, i have a form that can be influenced with up and down
Hey guys, this is simple but I can't make it workn... blah! I have
Hey guys! Can you please advise me how to modify my .htaccess so that
Hey guys, if anybody can help me out i'd love it... What i have
Hey guys, before you guys say anything I have searched and can not find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.