0

I need to make this circular menu with toggle instead of hover
i've tried https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_toggle_hide_show
but still it's not working and my circle position is really bad.
and this menu is from https://www.youtube.com/watch?v=4h9WH6YsMro&t=13s

My CSS :

body{
    background-color: #f273ba;
    font-family: tahoma;
    overflow: hidden;
}
.navbar{
    width: 150px;
    height: 150px;
    line-height: 150px;
    border-radius: 50%;
    background: white;
    margin: 190px auto;
    position: relative;
    cursor: pointer;
    text-align: center;
    font-size: 2.75em;
    font-weight: bold;
    color: #f273ba;
    transition: 0.24s 0.2s;
}
.navbar .menu{
    list-style: none;
    padding: 0;
    margin: 0;
    position: absolute;
    top: -75px;
    left: -75px;
    border: 150px solid transparent;
    cursor: default;
    border-radius: 50%;
    transform: scale(0);
    transition: transform 1.4s 0.07s;
    z-index: -1;
}
.navbar .menu.active{
    transition: transform 0.4s 0.08s, z-index 0s 0.5s;
    transform: scale(1);
    z-index: 1;
}

.navbar .menu li{
    position: absolute;
    top: -100px;
    left: -100px;
    transform-origin: 100px 100px;
    transition: all 0.5s 0.1s;
}

.navbar:active .menu li{
    transition: all 0.7s;
}
.navbar .menu li a {
    width: 45px;
    height: 45px;
    line-height: 45px;
    border-radius: 50%;
    background: white;
    position: absolute;
    font-size: 59%;
    color: #f273ba;
    transition: 0.7s;
}

.navbar:hover .menu li:nth-child(1){
    transition-delay: 0.02s;
    transform: rotate(85deg);
}
.navbar:hover .menu li:nth-child(1) a{
    transition-delay: 0.04s;
    transform: rotate(635deg);
}
.navbar:hover .menu li:nth-child(2){
    transition-delay: 0.04s;
    transform: rotate(125deg);
}
.navbar:hover .menu li:nth-child(2) a{
    transition-delay: 0.08s;
    transform: rotate(595deg);
}
.navbar:hover .menu li:nth-child(3){
    transition-delay: 0.06s;
    transform: rotate(165deg);
}
.navbar:hover .menu li:nth-child(3) a{
    transition-delay: 0.12s;
    transform: rotate(555deg);
}
.navbar:hover .menu li:nth-child(4){
    transition-delay: 0.08s;
    transform: rotate(205deg);
}
.navbar:hover .menu li:nth-child(4) a{
    transition-delay: 0.16s;
    transform: rotate(515deg);
}
.navbar:hover .menu li:nth-child(5){
    transition-delay: 0.1s;
    transform: rotate(245deg);
}
.navbar:hover .menu li:nth-child(5) a{
    transition-delay: 0.2s;
    transform: rotate(475deg);
}
.navbar:hover .menu li:nth-child(6){
    transition-delay: 0.12s;
    transform: rotate(285deg);
}
.navbar:hover .menu li:nth-child(6) a{
    transition-delay: 0.24s;
    transform: rotate(435deg);
}
.navbar:hover .menu li:nth-child(7){
    transition-delay: 0.14s;
    transform: rotate(325deg);
}
.navbar:hover .menu li:nth-child(7) a{
    transition-delay: 0.28s;
    transform: rotate(395deg);
}
.navbar:hover .menu li:nth-child(8){
    transition-delay: 0.16s;
    transform: rotate(365deg);
}
.navbar:hover .menu li:nth-child(8) a{
    transition-delay: 0.32s;
    transform: rotate(355deg);
}
.navbar:hover .menu li:nth-child(9){
    transition-delay: 0.18s;
    transform: rotate(405deg);
}
.navbar:hover .menu li:nth-child(9) a{
    transition-delay: 0.36s;
    transform: rotate(315deg);
}
a,a:active {
    text-decoration: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Circular menu onclick</title>
    <link rel='stylesheet' href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
    <div class="navbar">MENU
        <ul class="menu" onclick="click()">
            <li><a href="https://www.facebook.com/" class="fa fa-facebook"></a></li>
            <li><a href="https://twitter.com/home?lang=en" class="fa fa-twitter"></a></li>
            <li><a href="https://www.linkedin.com/" class="fa fa-linkedin"></a></li>
            <li><a href="https://www.google.com/" class="fa fa-google-plus"></a></li>
            <li><a href="https://rss.com/" class="fa fa-rss"></a></li>
            <li><a href="https://id.pinterest.com/" class="fa fa-pinterest"></a></li>
            <li><a href="https://www.skype.com/en/features/skype-web/" class="fa fa-skype"></a></li>
            <li><a href="https://github.com/" class="fa fa-github"></a></li>
            <li><a href="https://www.instagram.com/?hl=id" class="fa fa-instagram"></a></li>
        </ul>
    </div>
</body>
</html>

6
  • 1
    Welcome to Stack Overflow! Where is your JS? Commented Jan 26, 2021 at 15:18
  • You will need to add some Javascript which will define the function 'click()'. Commented Jan 26, 2021 at 15:26
  • here's what i have tried but this is messy i don't know how to fix it Commented Jan 26, 2021 at 15:32
  • <script> function clickMenu() { var x = document.getElementsByClassName('navbar'); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; } } </script> Commented Jan 26, 2021 at 15:32
  • I used button on this one Commented Jan 26, 2021 at 15:32

1 Answer 1

0

use this for toggle onclick so you basically need to use toogle and querySelector instead and you need to change the :hover to .active btw this is my first account for people who try to answered thank you <3

<script type="text/javascript">
    function toggleMenu() {
       var navigation = document.querySelector(".navbar");
       var menuToggle = document.querySelector(".toggle");
       var menu = document.querySelector(".menu");
       navigation.classList.toggle("active");
       menuToggle.classList.toggle("active");
       menu.classList.toggle('active');
    }
    </script>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.