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 9135911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:53:02+00:00 2026-06-17T08:53:02+00:00

I really didn’t know how to come up with a descriptive title for this.

  • 0

I really didn’t know how to come up with a descriptive title for this. Pretty much what I’m trying to do is make this accordion list item jump to the other side of the page when clicked. Currently the accordion is opening from left to right – but the last cell doesn’t jump right it instead stays in place. How can I make that last cell jump to the right instead of staying in place.

The point of this is to put a picture in the tabs and have them come together at the beginning and end of browsing links.

JSFiddle Example – click the last cell

HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Accordion</title>
    <link rel="stylesheet" type="text/css" href="redo.css" />
</head>
<body>
    <div id="hc1" class="haccordion">
        <ul>
            <li>
                <div class="hpanel">
                    <div class="preview" id="p1"></div>
                    <div class="contentContainer">
                        <div class="content">

                        </div>
                    </div>
                </div>
            </li>

            <li>
                <div class="hpanel">
                    <div class="preview" id="p2"></div>
                    <div class="contentContainer">

                    </div>
                </div>
            </li>

            <li>
                <div class="hpanel">
                    <div class="preview" id="p3"></div>
                    <div class="contentContainer">

                    </div>
                </div>
            </li>

            <li>
                <div class="hpanel">
                    <div class="preview" id="p4"></div>
                    <div class="contentContainer">
                    asdf
                    </div>
                </div>
            </li>

            <li>
                <div class="hpanel">
                    <div class="preview" id="p5"></div>
                    <div class="contentContainer">

                    </div>
                </div>
            </li>
        </ul>
    </div>
<!-- Scripts -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="accordion.js"></script>
<!-- End Scripts -->
</body>

CSS

*
{
    margin:0px;
    padding:0px
}

html, body
{
    height:100%;
    width: 100%;
}

#hc1, #hc1 ul, #hc1 li
{
    height: 100%;
}

#hc1, #hc1 ul 
{
    width: 100%;
}

.preview
{
    width: 50px;
    float: left;
    height: 100%;
    background-color: #E48525
}

#p1{background-color: #231F20}
#p2{background-color: #4F4E4F}
#p3{background-color: #919191}
#p4{background-color: #C4C4C3}
#p5{background-color: #E8E8E8}
/*
#p1{background-color: red}
#p2{background-color: blue}
#p3{background-color: green}
#p4{background-color: black}
#p5{background-color: orange}
*/
.contentContainer
{
    background-color: gray;
    margin: 0 auto;
    width: 100%;
    height: 100%;
}

/* -- Start Accordion -- */
.haccordion{
padding: 0;
}

.haccordion ul{
margin: 0;
padding: 0;
list-style: none;
overflow: hidden; /*leave as is*/
}

.haccordion li{
margin: 0;
padding: 0;
display: block; /*leave as is*/
overflow: hidden; /*leave as is*/
float: left; /*leave as is*/
}
/* -- End Accordion -- */

Javascript

var haccordion={
    //customize loading message if accordion markup is fetched via Ajax:
    ajaxloadingmsg: '<div style="margin: 1em; font-weight: bold"><img src="ajaxloadr.gif" style="vertical-align: middle" /></div>',

    accordioninfo: {}, //class that holds config information of each haccordion instance

    expandli:function(accordionid, targetli){
        var config=haccordion.accordioninfo[accordionid]
        var $targetli=(typeof targetli=="number")? config.$targetlis.eq(targetli) : (typeof targetli=="string")? jQuery('#'+targetli) : jQuery(targetli)
        if (typeof config.$lastexpanded!="undefined") //targetli may be an index, ID string, or DOM reference to LI
        {
            config.$lastexpanded.stop().animate({width:config.paneldimensions.peekw}, config.speed); //contract last opened content
            config.$lastexpanded.removeClass('active');
        }
        $targetli.stop().animate({width:$targetli.data('hpaneloffsetw')}, config.speed) //expand current content
        config.$lastexpanded=$targetli
        if($targetli.attr('class') != 'active')
        $targetli.addClass('active');
    },


    urlparamselect:function(accordionid){
        var result=window.location.search.match(new RegExp(accordionid+"=(\\d+)", "i")) //check for "?accordionid=index" in URL
        if (result!=null)
            result=parseInt(RegExp.$1)+"" //return value as string so 0 doesn't test for false
        return result //returns null or index, where index is the desired selected hcontent index
    },

    getCookie:function(Name){
        var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
            return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
    },

    setCookie:function(name, value){
        document.cookie = name + "=" + value + "; path=/"
    },


    loadexternal:function($, config){ //function to fetch external page containing the entire accordion content markup
        var $hcontainer=$('#'+config.ajaxsource.container).html(this.ajaxloadingmsg)
        $.ajax({
            url: config.ajaxsource.path, //path to external content
            async: true,
            error:function(ajaxrequest){
                $hcontainer.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText)
            },
            success:function(content){
                $hcontainer.html(content)
                haccordion.init($, config)
            }
        })
    },


    init:function($, config){
            haccordion.accordioninfo[config.accordionid]=config //cache config info for this accordion
            var $targetlis=$('#'+config.accordionid).find('ul:eq(0) > li') //find top level LIs
            config.$targetlis=$targetlis
            config.selectedli=config.selectedli || [] //set default selectedli option
            config.speed=config.speed || "normal" //set default speed

//KEY_CHANGE_BEGIN
            var maxWidth    = $targetlis.parent ().width ();
            $targetlis.each ( function () { maxWidth -= $(this).outerWidth (true); } );

            $targetlis.each(function(i){
                var $target=$(this).data('pos', i) //give each li an index #

                var lclMaxWidth     = maxWidth + $target.find ('.hpanel:eq(0)').outerWidth (true);
                $target.css ('width', config.paneldimensions.fullw);

                //get offset width of each .hpanel DIV (config.dimensions.fullw + any DIV padding)
                var hpaneloffsetw   = $target.find ('.hpanel:eq(0)').outerWidth (true);
                if (hpaneloffsetw > lclMaxWidth)
                    hpaneloffsetw   = lclMaxWidth;

                $target.data('hpaneloffsetw', hpaneloffsetw);
                $target.css ('width', '');
//KEY_CHANGE_END

                $target.click(function(){
                        haccordion.expandli(config.accordionid, this)
                    config.$lastexpanded=$(this);
                })
                if (config.collapsecurrent){ //if previous content should be contracted when expanding current
                        config.$lastexpanded.removeClass('active');
                    $target.click(function(){
                        $(this).stop().animate({width:config.paneldimensions.peekw}, config.speed); //contract previous content
                    })
                }
            }) //end $targetlis.each
            var selectedli=haccordion.urlparamselect(config.accordionid) || ((config.selectedli[1] && haccordion.getCookie(config.accordionid))? parseInt(haccordion.getCookie(config.accordionid)) : config.selectedli[0])
            selectedli=parseInt(selectedli)
            if (selectedli>=0 && selectedli<config.$targetlis.length){ //if selectedli index is within range
                config.$lastexpanded=$targetlis.eq(selectedli)
                config.$lastexpanded.css('width', config.$lastexpanded.data('hpaneloffsetw')) //expand selected li
            }
            $(window).bind('unload', function(){ //clean up and persist on page unload
                haccordion.uninit($, config)
            }) //end window.onunload
    },

    uninit:function($, config){
        var $targetlis=config.$targetlis
        var expandedliindex=-1 //index of expanded content to remember (-1 indicates non)
        $targetlis.each(function(){
            var $target=$(this)
            $target.unbind()
            if ($target.width()==$target.data('hpaneloffsetw'))
                expandedliindex=$target.data('pos')
        })
        if (config.selectedli[1]==true) //enable persistence?
            haccordion.setCookie(config.accordionid, expandedliindex)
    },

    setup:function(config){
        //Use JS to write out CSS that sets up initial dimensions of each LI, for JS enabled browsers only
        document.write('<style type="text/css">\n')
        document.write('#'+config.accordionid+' li{width: '+config.paneldimensions.peekw+';\nheight: '+config.paneldimensions.h+';\n}\n')
        document.write('#'+config.accordionid+' li .hpanel{width: '+config.paneldimensions.fullw+';\nheight: '+config.paneldimensions.h+';\n}\n')
        document.write('<\/style>')
        jQuery(document).ready(function($){ //on Dom load
            if (config.ajaxsource) //if config.ajaxsource option defined
                haccordion.loadexternal($, config)
            else
                haccordion.init($, config)
        }) //end DOM load
    }
}

haccordion.setup({
    accordionid: 'hc1', //main accordion div id
    paneldimensions: {peekw:'50px', fullw:'100%', h:'100%'},
    selectedli: [4, false], //[selectedli_index, persiststate_bool]
    collapsecurrent: false //<- No comma following very last setting!
})
  • 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-06-17T08:53:03+00:00Added an answer on June 17, 2026 at 8:53 am

    Here it is: tinker.io/f7fe4/12

    This is the simplest change of all of the versions, requiring only floating the first preview to the right. Can be done programatically or with css (can be buggy in IE7+):

    $('#hc1 li .preview').first().css('float','right');
    

    or

    #hc1 li:first-child .preview {
        float:right;
    }
    

    —

    Is this the kind of effect you’re looking for?

    https://tinker.io/f7fe4/8

    Here’s the same kind of affect, with a ‘smoother’ animation (it keeps the outer div still on the screen however)

    https://tinker.io/f7fe4/9

    And this is what I thought you were talking about at first

    https://tinker.io/f7fe4/4 (this pops the left most cell over to the right and opens it, kind of like an infinite slider)

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

Sidebar

Related Questions

i didn't really know how to title this question, but here's a thing that
I really didn't know how to write the title for this problem :P So
I really didn't know what title to give this question, but I'll explain here:
Sorry for the title, I really didn't know how to say this... I often
Sorry for the vague title but I really didn't know what title to give
Apologies if this has been asked before but I really didn't know what to
I really didn't know how to ask this question in a simple fashion. I
I really didn't know what title I should choose. Anyway, I have code like
Ok I really didn't know how else to sum it up for the title.
I really didn't know how to specify the problem in the title, so here's

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.