1



The following is a nice "Drop Down Panel" by dynamic drive. http://www.dynamicdrive.com/dynamicindex17/dddropdownpanel.htm

as you can see, it's a panel that pushes the content of the "body" when opening, in "top-down" direction.
i'd like to know if it's possible to change its code in order to have a sliding(side) panel with "right-left" or "left-right" direction, which pushes the "body" content while opening?

thanks in advance

light-blue
  • 254
  • 3
  • 12
  • 1
    It should be doable but not sure it will work out as nicely as you think. Your options would either be to push the main content outside of the visible space (clipping part of it) and maintain it's width or make it's width less in order to make room for the side bar (which will reflow all the stuff inside causing shifting and whatnot). – Matt Berkowitz May 20 '13 at 21:57

2 Answers2

1

I wouldn't advise using that plugin to do what you want to achieve- if I understand you correctly, the effect you want, can be built yourself reasonably simply using jQuery and absolute positioning in CSS..

<div class="container">
  <a href="#2" class="toggle">toggle</a>
  <div class="hidden">
  </div>
  <div class="body">
  </div>
</div>


.container {position:relative; } 

Position relative means that elements contained will use this as a reference

.hidden {
  width:50px; 
  height:300px; 
  background:pink;
  position:absolute; 
  left:0;z-index:10;
} 

Then position this element absolutely 0 to the left of our reference element and with a z-index to ensure it appears above body element when it is extended.

.body {width:500px; height:300px; background:grey; float:left;}

Finally you need to include jQuery on your page and use something like the following function.

$('.toggle').click(function(){
    if (open != true){
         $(".hidden").animate({width:'300px'}, 500);
         open = true;
    }
    else
    { 
         $(".hidden").animate({width:'50px'}, 500);
         open = false;
    }
    return false;
});

Which will select your a.toggle element, and set a click event up on it. When this fires for the first time open will not have been defined so will not (!=) be true. Then we can animate (api.jquery.com/animate/) the width to the the desired size over 500ms and declare our open variable within the scope of this function to be true. The next time we fire the click event on this particular function, the second section after the } else { will fire instead.

You can try a demo over on http://jsfiddle.net/DcWS2/ . If this isn't quite what your going for, then I'm happy to help further.

EDIT

A more complete solution to your question could look like (http://jsfiddle.net/DcWS2/3/)

$('.hidden').hover(function(){
    $(".hidden").stop().animate({width:'200px'}, 500);
    $(".body").stop().animate({marginLeft:'200px'}, 500);
},function(){ 
    $(".hidden").stop().animate({width:'30px'}, 500);
    $(".body").stop().animate({marginLeft:'30px'}, 500);
});
happilyUnStuck
  • 372
  • 3
  • 18
  • Reading your question again, the exact effect you describe can be found as part of Foundation 3 (http://zurb.com/playground/off-canvas-layouts). The answer is a simplified implementation since it appears you are learning. You could imitate this functionality on a fixed width layout further by modifying the function above to also include `$('.body').animate({left:300px},500);` which would make quite a good exercise to cement your understanding. – happilyUnStuck May 20 '13 at 22:43
  • @Stano nice! +1 for .stop(), reworked your margin code to use wideth in tandem. It actually looks pretty smart when you add text in the main section. http://jsfiddle.net/DcWS2/3/ – happilyUnStuck May 20 '13 at 23:37
  • @happilyUnStuck thanks for your helpful answer, codes and comments, they're great, However i'd like to use simpler javascript than using JQuery, as i have had many issues with Internet Explorer (versions 7,8 and 9) when using JQuery, and sometimes the results are completely different than what one might see in FireFox, Chrome and Opera. – light-blue May 21 '13 at 19:24
  • @Stano thanks for your solution, Yes, you're right, i'm not using JQuery, and i'm gonna push the contents of the body when opening the menu, your solution is nice, however, is it still using jQuery? – light-blue May 21 '13 at 20:00
  • @happilyUnStuck thanks for your help again, and one more question; is it so hard to do what you've done in the __http://jsfiddle.net/DcWS2/3__ without jQuery? – light-blue May 21 '13 at 20:02
  • Yes, [it](http://jsfiddle.net/DcWS2/4/show) still uses jquery. You can try this alternative instead: http://pastebin.com/xq9jc1Fz (it only requires a small animation library anim.min.js (2.75KB) - can be downloaded from https://github.com/relay/anim ). The script from dynamicdrive is quite advanced, uses cookies and images and is not simple to rework it to horizontal slider. Anyway good luck light and happily! – Stano May 22 '13 at 00:37
  • @light-blue It's possible to so without jQuery, I use it mostly for it's effective selection $('#anything') and for the ability to chain().alot().of().different functions. The essential logic of my code would work without it, although the selectors and methods would need to be rewritten in pure javascript. – happilyUnStuck May 22 '13 at 08:21
  • 1
    While I cannot claim to be an expert in this area, it's possible that it is your code and not jQuery is fault with the [IE issue's](http://stackoverflow.com/questions/784391/jquery-show-not-working-in-ie7) The other browsers are sometimes more forgiving with the way they interpret code, but generally I find jQuery to be fairly robust when working across platforms. – happilyUnStuck May 22 '13 at 08:22
  • 1
    The size of the library is not usually of concern for me, as most third party software I use tends to have jquery included, and in general it takes about as much to load as a .jpg - if you want to post the trouble you are having with jquery as another question I would be happy to have a look, but as far as pure javascript is concerned, I'm not a huge fan, as it feels a little bit too much like hard work to me =) – happilyUnStuck May 22 '13 at 08:25
  • @Stano thanks for your new codes, i think i should try to see if it's possible to push **body**'s contents as well while opening the menu or not :) – light-blue May 22 '13 at 09:05
  • @happilyUnStuck thanks a lot for your codes, they're awesome. I also agree with you about the jQuery and IE; most of the time it's more about IE than jQuery, as the codes (written with jQuery) work smoothly on other browsers but IE. – light-blue May 22 '13 at 09:06
  • @happilyUnStuck Yes, this would be cumbersome, to use plain JS, and i think one should avoid this :), however, i thought it might have been easy to do some trick on DynamicDrive code to have a horizontal sliding panel that works smoothly on IE, as well as other browser. It seems that i was wrong ;) – light-blue May 22 '13 at 09:09
  • @Stano . happilyUnStuck , actually, i was using the following code, http://dzyngiri.com/demo/sliding-panel-menu-using-jQuery It's a very easy one and its result is very satisfying. The only issue was that i hadn't checked it on IE. After i found out it has problem with all versions of IE except its latest version (v.10), i started looking for a simpler code, and i found that DynamicDrive one. – light-blue May 22 '13 at 09:18
  • @happilyUnStuck , Stano, I have also found some of examples from jQueryMobile.com not working on all versions of Internet Explorer except version 10. for example you can give this one a try: http://jquerymobile.com/demos/1.3.0-beta.1/docs/panels/ – light-blue May 22 '13 at 09:30
1

Not sure exactly how you would do this with Dynamic Drive, but you could do it very easily with jQuery show/hide:

HTML:

<div id="helpPanel">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
<a href="#" id="button" class="ui-state-default ui-corner-all">Toggle Effect</a>
<div class="normal">
    Maecenas ultrices feugiat nibh sit amet mattis. Nullam et sapien id turpis tempus tincidunt non ac sapien.
</div>

CSS:

#helpPanel {  border: 1px solid red; overflow: auto; display: none; }
.normal { margin-top: 15px; border: 1px solid blue; }

JavaScript:

var state = true;
var $panel = $("#helpPanel");
$("#button").on("click" ,function() {
    if ( state ) {
        $panel.show(1000);
    } else {
        $panel.hide(1000);
    }
    state = !state;
});

Working Demo

Andreas Josas
  • 242
  • 2
  • 7
  • Andreas Josas, thanks for your post, it's a great sliding menu, however, i need some side panel, which opens **horizontally**, and also **without** any use of _"JQuery"_, (as i have had many issues with Internet Explorer browsers when using JQuery.) – light-blue May 21 '13 at 19:32