I have created a fiddle of a css or possibly jquery issue that I am facing. In the close position, the slider tab displays the text for the open and close positions simultaneously.
I request anyone to have a look and suggest a resolve.
$("#toggle a").click(function () {
$("#toggle a").toggle();
var state = $('#close').css('display');
//alert(state);
if(state === 'none') $('#close').css('display','block');
if(state === 'block') $('#close').css('display','none');
});
The state value always stays the same. I think one easier solution might be to add a class value called opened and closed and add it to the #paneldiv element depending on what state the slider is in. The selector style rule for that div will always be something like #panel.opened or #panel.closed.
In your CSS, you can have the following style rules that will toggle the visibility of your Open or Close links appropriately:
Thanks for that reply. This slider issue is haunting me since the last few days and I am glad to receive a reply from The Kirupa !! .Please bear in mind that I have limited knowledge of css while reading my reply.
Are you saying that I need not bother with the jquery at all and that the changes should be made in css. Why do we need both panel.opened and panel.closed ? Doesn’t one state automatically signify another? Where should I put panel.opened and panel.closed in the HTML ? What about the tab a.close and tab a.open classes? Won’t they be needed anymore ( their display attributes ) then?
I am actually quite confused by your reply as I guess I should be - the reply coming from an expert !!
The reason is that you are using the closed and opened class values as signals to our CSS to indicate the slider position. You could definitely just use one, but I prefer being explicit about what happens in each state. It’s just personal preference
I’m a bit swamped right now to solve your problem fully, but I’ll take a look in a little bit - unless somebody else jumps in first!
I too will continue to try and sort this out. If I am able to find a solution i’ll definitely post it here. Meanwhile I request some other experts to also kindly have a look to resolve this issue.
Reducing the slider to an even more minimal state, I realize that the issue is an initial condition problem where somehow initially both the open and close button texts show up together. If I can get the right text to show up or rather get the wrong text to somehow disappear initially, then the issue would be solved.
Still, I am unable, with my limited knowledge of css, to solve this even after numerous hit and trials. Kindly find some time to help me fix this. I am sure it would be easy for the experts now.
This was a fun one! I simplified your code a bit to avoid having extra logic for toggling the appearance of the Log-in and Close text. Instead, I tied the toggling logic to the menu opening and closing functions. Your revised JS would look like this:
Thanks loads for that solution. I have not completely understood it yet. I’ll spend time on it and revert. Meanwhile just wanted to let you know that I am grateful for the time you spent on this.
I’m working on a tutorial that shows how to create this effect using regular JS and CSS (no jQuery). Not sure when I’ll be done with it, but it will be soon
Well, I would like to thank both of you. Actually, I was also stuck in the same issue since 5 days, but after reading your solution I guess my issue will be solved.
Hope you are good. I was thinking that this is done but I overlooked yet another issue, seemingly small, but looks a bit complicated to me. Find here a new fiddle with a slightly modifies code. https://jsfiddle.net/ajoo/38qm9hou/2/.
It shows a login form in the slider ( when the slider is opened) with a login button.
Normally : When the slider slides down the message on the tab is Close Panel.
However if the user makes a mistake in filling the form or submits and empty form, the slider toggles and remains open but the message shown changes to Log In | Register which should actually now still be Close Panel since the slider is down and the panel is showing the Login form.
However I think there is no way I can show this behavior on fiddle since I don’t think it handles form submission. But I like I said, on error occurring on form submission, the panel is open and the message is Log In | Register which should actually be Close Panel.
I hope I have been able to explain this well in a simple manner. Looking forward to some help from you once again. Thanks loads.
I think if the CSS can be changed through JQuery using something like $('#close').text('Close Panel');, then I suppose this issue can be easily resolved. But for that I would have to know some condition, like maybe the state the panel currently is in.
I need not worry about the value when the panel is closed since that is not creating any issues ( or at least not yet and I think that won’t create any issues). So all I need to do here is to check the panel state and if it is open, set the text value to Close Panel.
I don’t know how to figure out the state of the panel. Please help me to achieve this.