Having trouble with a jQuery function that keeps triggering the second function every time I click. How can I fix this issue?
I designed a navbar with 3 links, each linked to a different .contentDiv with unique IDs. Whenever a link is clicked, a toggle function occurs: hiding all other .contentDiv elements except for the one linked to the clicked link, accompanied by a sliding animation to the left.
Sample HTML:
.navbar
ul
li
a.about(href='#') About
span
span
li
a#portfolio(href='#') HOME
span
span
li
a(href='#') Contact
span
span
.contentDiv#portfolioContent
.title About
.content
.fse
p Lorem ipsum dolor sit amet, consectetur adipiscing elit.
CSS:
.contentDiv {
transform: skew(45deg);
width: 100%;
height: 100%;
position: relative;
top: 5%;
left: 300%;
overflow: hidden;
}
.title {
position: absolute;
top: 30%;
left: 30%;
font-size: 500%;
font-family: Raleway;
font-weight: 800;
color: #EAEBED;
}
.content {
width: 100%;
height: 50%;
top: 43%;
left: 3%;
font-size: 130%;
font-family: Raleway;
color: #EAEBED;
position: absolute;
overflow:scroll;
padding-bottom: 7%;
}
JQuery:
$('.about').click(function () {
$("#aboutContent").toggle(
function() {
$("#aboutContent").animate({left: "115%"}, { //coming out of hiding
duration: 2000
});
}, function() {
$("#aboutContent").animate({left: "300%"}, { //back into hiding
duration: 2000
});
}
);
});