Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have written a slider come off from the side of my website and it's based on one clickble DIV. And it has a javascript given below.The issue is that when i press the div for the first time. it will do the job nicely, OK Now i opend it,and then close it.after that i click back to open back.
#good news is it will open
#bad news is it needs three clicks to run for the rest of the attempts.

$if you can solve this problem, i really appriciate it.

What I have tried:

function left_nav_slider_button(){
var status=true;
var open_close_swich=document.getElementById('open_close_swich').addEventListener('click',try_it,true)
open_close_swich.addEventListener("click",function(e){
e.preventDefault();
if (status===true){
$(this).parent().toggleClass('slidein_left');
status=false;
console.log('1st');
}
else
{
$(this).parent().toggleClass('slideout_left');
status=true;
console.log('2nd');
}
});
}
}
Posted
Comments
OriginalGriff 22-Nov-17 4:06am    
Comment from Anil Bandela, posted as a "solution":

Quote:Please add your java script code in document.ready() that help you..
Richard Deeming 22-Nov-17 12:51pm    
At a guess, you need to remove the slideout_left class when you add the slidein_left class, and vice-versa.
$(this).parent().toggleClass('slidein_left', status).toggleClass('slideout_left', !status);
status = !status;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900