Skip to main content

Add scroll to drop down menu

How do I add a scroll to this drop down menu? Currently, the menu overflows when it is in drop down mode and some of the menu items can't be seen. It is meant to scroll when the menu exceeds the screen height to reveal all the menu items. I used overflow:scroll on the li element but it did not create the desired result. What's the best way to achieve a scroll on the menu. Thanks.

This is the HTML

<html>
<head>
    <link rel="stylesheet" href="style.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body>

    <header class="site-header menu-text">
        <a href="#" id='drop'><i class="fa fa-bars"></i></a>
        <nav>
            <ul>
                <li>Menu 1</li>
                <li>Menu 2</li>
                <li>Menu 3</li>
                <li>Menu 4</li>
                <li>Menu 5</li>
                <li>Menu 6</li>
                <li>Menu 7</li>
                <li>Menu 8</li>
                <li>Menu 9</li>
                <li>Menu 10</li>
            </ul>
        </nav>
    </header>

    <div class="container"></div>
    
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'></script>
    <script src="script.js"></script>
</body>
</html>

This is the script.js

(function($){
    var dropper = $("a#drop"),
        menu = $("nav>ul"),
        subMenu = $("nav>ul>li.submenu"),
        link = menu.find("li");

        dropper.on("click" , function(e){
            $( this ).toggleClass( 'active' );
            menu.slideToggle();
            e.preventDefault();
        });

        $(window).resize(function(){
            var winWidth = $(this).width();
            if(winWidth > 920 && menu.is(":hidden")){
                menu.removeAttr("style");
            }
        });

        link.on("click" , function(){
            var winWidth = $(window).width();
            if(winWidth < 920 && !$(this).hasClass("submenu")){
                menu.slideToggle(); 
            }
        });
        subMenu.hover(function(){
            $(this).children("ul").stop().slideDown();
        },function(){
            $(this).children("ul").stop().slideUp();
        });
})(jQuery);

And this is the style.css

.site-header {
    width: 100%;
    height: 75px;
    position: fixed;
    top: 0;
    z-index: 12;
    overflow: visible;
    background-color: purple;
}

.site-header a#drop {
    background-color: white;
    padding: 20px 15px;
    margin: 10px 15px;
    float: right;
    display: block;
}

@media screen and (min-width: 920px) {
    .site-header a#drop {
        display: none;
    }
}

.site-header nav {
    float: right;
    margin-bottom: 100px;
    width: 100%;
    margin-top: 5px;
    background-color: green;
    opacity:0.7;
}

@media screen and (min-width: 920px) {
    .site-header nav {
        float: none;
        margin-top: 0px;
    }
}

.site-header nav ul {
    display: none;
    padding: 0;
    margin-top: 20px;
    overflow: scroll;
}

@media screen and (min-width: 920px) {
    .site-header nav ul {
        float: right;
        display: block;
        margin-top: 0px;
        overflow: hidden;
    }
}

.site-header nav ul li {
    position: relative;
    z-index: 2;
    float: left;
    display: block;
    text-align: left;
    text-indent: 10px;
    width: 100%;
    margin-left: 0;
    height: auto;
    padding: 12px 0 12px;
    color:white;
    font-weight:bold;
}

@media screen and (min-width: 920px) {
    .site-header nav ul li {
        display: inline-block;
        margin: 0;
        text-align: center;
        padding: 0 8px;
        height: 76px;
        width: auto;
        text-indent: 0;
    }
}

.container{
    background-image:repeating-linear-gradient(#f8ea00, #f8ea00 30px, #005bf7 10px, #005bf7 70px);
    height:600px;
    } 
Via Active questions tagged javascript - Stack Overflow https://ift.tt/SHV0ArW

Comments

Popular posts from this blog

ValueError: X has 10 features, but LinearRegression is expecting 1 features as input

So, I am trying to predict the model but its throwing error like it has 10 features but it expacts only 1. So I am confused can anyone help me with it? more importantly its not working for me when my friend runs it. It works perfectly fine dose anyone know the reason about it? cv = KFold(n_splits = 10) all_loss = [] for i in range(9): # 1st for loop over polynomial orders poly_order = i X_train = make_polynomial(x, poly_order) loss_at_order = [] # initiate a set to collect loss for CV for train_index, test_index in cv.split(X_train): print('TRAIN:', train_index, 'TEST:', test_index) X_train_cv, X_test_cv = X_train[train_index], X_test[test_index] t_train_cv, t_test_cv = t[train_index], t[test_index] reg.fit(X_train_cv, t_train_cv) loss_at_order.append(np.mean((t_test_cv - reg.predict(X_test_cv))**2)) # collect loss at fold all_loss.append(np.mean(loss_at_order)) # collect loss at order plt.plot(np.log(al...

Sorting large arrays of big numeric stings

I was solving bigSorting() problem from hackerrank: Consider an array of numeric strings where each string is a positive number with anywhere from to digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array. I know it works as follows: def bigSorting(unsorted): return sorted(unsorted, key=int) But I didnt guess this approach earlier. Initially I tried below: def bigSorting(unsorted): int_unsorted = [int(i) for i in unsorted] int_sorted = sorted(int_unsorted) return [str(i) for i in int_sorted] However, for some of the test cases, it was showing time limit exceeded. Why is it so? PS: I dont know exactly what those test cases were as hacker rank does not reveal all test cases. source https://stackoverflow.com/questions/73007397/sorting-large-arrays-of-big-numeric-stings

How to load Javascript with imported modules?

I am trying to import modules from tensorflowjs, and below is my code. test.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title </head> <body> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script> <script type="module" src="./test.js"></script> </body> </html> test.js import * as tf from "./node_modules/@tensorflow/tfjs"; import {loadGraphModel} from "./node_modules/@tensorflow/tfjs-converter"; const MODEL_URL = './model.json'; const model = await loadGraphModel(MODEL_URL); const cat = document.getElementById('cat'); model.execute(tf.browser.fromPixels(cat)); Besides, I run the server using python -m http.server in my command prompt(Windows 10), and this is the error prompt in the console log of my browser: Failed to loa...