My goal is to trigger an animation that involves text sliding off the screen only when the burger icon is clicked, rather than loading immediately upon refreshing the page. The desired behavior includes activating the function on the initial click and then reversing it if the icon is clicked again, with the first character ('C') re-entering the display first.
jQuery("#button").click(function() {
jQuery(".line1").toggleClass("open1");
jQuery(".line2").toggleClass("open2");
jQuery(".line3").toggleClass("open3");
});
(function text_loop(i) {
setTimeout(function() {
if (i <= 15)
$("#logo_text span").eq(i).addClass("slide_out");
i++;
text_loop(i);
}, 100);
})(0);
#burger_container {
background-color: #404041;
display: block;
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 60px;
z-index: 101;
}
svg {
margin: 20px auto 0 auto;
display: block;
}
#logo_text {
transform: rotate(-90deg);
margin-top: 350px;
font-size: 40px;
color: #ffffff;
font-weight: 700;
}
#logo_text span {
font-weight: 400;
position: relative;
top: 0;
transition: top 1s ease;
}
#logo_text span.slide_out {
top: -60px;
transition: top 0.5s ease;
}
.line1,
.line2,
.line3 {
transition: all 0.3s ease;
}
.open1 {
transform-origin: top left;
transform: translatex(3px) translatey(-1px) rotate(45deg);
width: 33px;
}
.open2 {
opacity: 0;
}
.open3 {
transform-origin: bottom left;
transform: translatex(3px) translatey(1px) rotate(-45deg);
width: 33px;
}
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<div id="burger_container">
<div>
<svg id="button" style="height: 26px; width: 26px;">
<g style="" fill="#f04d43">
<rect class="line1" x="0" y="1" rx="2" ry="2" width="26px" height="4px" />
<rect class="line2" x="0" y="11" rx="2" ry="2" width="26px" height="4px" />
<rect class="line3" x="0" y="21" rx="2" ry="2" width="26px" height="4px" />
</g>
</svg>
<div id="logo_text"><span>C</span><span>o</span><span>m</span><span>p</span><span>a</span><span>n</span><span>y</span> <span>W</span><span>o</span><span>r</span><span>k</span><span>f</span><span>o</span><span>r</span><span>c</span><span>e</span></div>
</div>
</div>