jquery를 이용해서 공지사항등 기타 메뉴를 돌리면서 볼수있게 처리

 

js

$(document).ready(function() {
    $('ul > li:first-child').addClass('active');   
    $('.list-btn').click(function() {
        if($(this).hasClass('up')){
            if ($('ul > li:first-child').hasClass('active')) {
                $('ul > li:first-child').removeClass("active");
                $('ul > li:last-child').addClass("active");
            } else {
                $('li.active').prev().addClass("active").siblings().removeClass("active");
            }
        } else {
            if ($('ul > li:last-child').hasClass('active')) {
                $('ul > li:last-child').removeClass("active");
                $('ul > li:first-child').addClass("active");
            } else {
                $('li.active').next().addClass("active").siblings().removeClass("active");
            }
        }
    });
});

 

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vertical-menu</title>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <link href="/style.css" rel="stylesheet" />
</head>
<body>
    <h3 class="text-center text-info mt-4">Vertical Menu</h3>
    <ul>
        <li>Cras justo odio</li>
        <li>Dapibus ac facilisis in</li>
        <li>Morbi leo risus</li>
        <li>Porta ac consectetur ac</li>
        <li>Vestibulum at eros</li>
        <li>Morbi leo risus</li>
        <li>Porta ac consectetur ac</li>
        <li>Vestibulum at eros</li>        
    </ul>
    <div class="col">
        <button class="btn btn-block btn-primary list-btn up">up</button>
        <button class="btn btn-block btn-primary list-btn down">down</button>
    </div>
    <script src="/app.js"></script>
</body>
</html>

 

css

ul {
    padding: 15px;
    margin: 30px 15px 15px;
    position: relative;
    height: 50px;
}

li {
    position: absolute;
    display: none;
    width: 100%;
    top:0;
    left: 0;
    padding: .75rem 1.25rem;
    margin: 0;
    background-color: #fff;
    border: 1px solid rgba(0,0,0,.125);    
    transition: .3s all;
    list-style: none;
}

li.active {
    display: block;
}