Mini-navigation bar scrolling

I am trying to create a menu where I want to hide elements if the length of either class a or class b is larger than the entire container. I want to achieve a similar effect to what Facebook has. How can I make this happen? I have thought about one approach mentioned in the comment section, but I am unsure of what steps to take next.

$('.b').hide();
     $(".a").click(function(){
        $(".b").slideToggle(200);
    });

/*
$(document).ready(function(){ 
   
    var k = $("#container").length;
var n = $(".a").length;
    
    
if (n > k) {

} 
else {

}

});
*/
#container
{
    width: 200px;
    height: 500px;
    background-color: rgba(0, 0, 0, 0.3);
}

ul
{
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.a
{
    width: 200px;
    height: 100px;
    margin-bottom: 10px;
    background-color: black;
    cursor: pointer;
}

.b
{
    margin-bottom: 5px;
    padding: 0;
    list-style-type: none;  
    height: 100px;
    width: 200px;
    background-color: rgba(0, 0, 0, 0.6);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<div id="container">
    <ul>
        <li class="a"></li>
            <ul>
                <li class="b"></li>
                <li class="b"></li>
                <li class="b"></li>
            </ul>
        <li class="a"></li>
        <li class="a"></li>
    </ul>
</div>

Answer №1

If you want the content in #container to have a scroll bar, simply add overflow-y: scroll; and adjust until it looks just right. Check out this interactive example.

Custom CSS Styles

#container {
    width: 200px;
    height: 500px;
    overflow-y: scroll;
    background-color: rgba(0, 0, 0, 0.3);
}
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
.a {
    width: 200px;
    height: 100px;
    margin-bottom: 10px;
    background-color: black;
    cursor: pointer;
}
.b {
    margin-bottom: 5px;
    padding: 0;
    list-style-type: none;
    height: 100px;
    width: 200px;
    background-color: rgba(0, 0, 0, 0.6);
}

HTML Structure

<div id="container">
    <ul>
        <li class="a"></li>
        <ul>
            <li class="b"></li>
            <li class="b"></li>
            <li class="b"></li>
        </ul>
        <li class="a"></li>
        <li class="a"></li>
    </ul>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Decorate the elements that do not contain a specific child class

I'm currently working on an angular project with primeng for the UI components. My focus at the moment is on customizing the p-menu component, specifically the appearance of list items that are not active. The challenge I'm facing is that the act ...

Convert a comma-delimited string containing a numerical value into a floating point number, for example, 3.00

I need to extract a number from a value that is returned with commas around it. My goal is to convert this value into a number so that I can compare it against another number in my code later on. However, I'm facing difficulties in reliably extracting ...

Creating a dynamic image viewing experience similar to Facebook's image viewer using jQuery

Here are two div tags that show the previous and next images from the large image collection: <div class="alignleft"><a href="1005.php"><img width="50" height="50" src="thumb-98.jpg" class="previous"></a></div> <div class ...

Change the color of specific elements in an SVG using React

Can I change the dynamic primary color from ReactJS to a specific class in an SVG file? If yes, how can it be done? Error.svg <!-- Generator: Adobe Illustrator 26.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> <svg version="1.1&qu ...

The Ajax request is stuck and not responding

I am currently working on an ajax call and controller function that involve creating a document in DocDb. Here is the code: $.ajax({ type: "POST", url: urlToGetRules, data: { ruleName: ruleName}, }) ...

Utilizing asynchronous operations in MongoDB with the help of Express

Creating a mobile application utilizing MongoDB and express.js with the Node.js MongoDB driver (opting for this driver over Mongoose for enhanced performance). I am aiming to incorporate asynchronous functions as a more sophisticated solution for handling ...

Is there a way for me to calculate the square of a number generated by a function?

Just starting out with Javascript and coding, I'm having trouble squaring a number that comes from a function. I've outlined below what I am trying to achieve. Thank you in advance for your help. // CONVERT BINARY TO DECIMAL // (100110)2 > ( ...

Troubleshooting the "@material-ui/core" issue in React: Step-by-step guide

Issue with React: Unable to locate the '@material-ui/core' module in 'C:\Users\user\Downloads\inTech'22-Web Development (EDUGEN)\edu-gen\src\components' Resolution Command: To resolve, run npm in ...

Encountering an issue while attempting to assess a Meteor package within a local environment

Hello everyone! I'm a beginner in Meteor programming and currently following the online book discovermeteor.com. I recently came across a chapter that covers the creation of Meteor Packages. Excitedly, I proceeded to create my own package using the ...

Text Alignment Issue in Icon Bar of Zurb Foundation 5

There's an unusual problem I'm encountering with the alignment of text under the icon bar not being properly centered below the icons. Here is a snippet of the code: <div class="row"> <div class="small-12 columns"> < ...

JavaScript Code to Remove an Element from an Array

I have a Javascript Filter Item Class and an array structured as follows: function FilterItem(filterId, filterType) { this.filterId = filterId; this.filterType = filterType; } var filterItemArray = []; To add Filter Items to this array, I use th ...

Detecting modifications to an array with MobX

Today marks my first foray into learning MobX and I am eager to discover how to track all array changes (insertions, deletions, etc) with MobX. A practical example would definitely help clarify this: const TodoList = ({todos}) => ( <ul> ...

Issue with SwiperJS not completely filling the height of a div

My issue relates to using swiperJS with multiple images, as I'm struggling to make it take the full width and height of the containing div. Despite applying styling like this to my images: .swiper-slide img { width: 100%; height: 1 ...

Identify the position of a mouse click event when dots overlap

Experience this live demo on CodePen by visiting it here. 1) When you click on the grid, a first red point will be added. 2) Click on the grid again to add a second red point. 3) By clicking back on the first red point, you may notice that the coordinat ...

Utilize a function or array to send various data with an Ajax post request

Hey, I'm on the hunt for a more efficient method to send data using ajax to php for multiple users. Take a peek at my code below: $(document).ready(function(){ $("#all").click(function(){ document.getElementById('babon').click(); ...

Why won't Vanilla JavaScript work with my Rails application?

Having trouble implementing a full screen menu, no Rails errors but not working when project is run. Error received: Cannot read property 'addEventListener' of null JS code snippet: (function() { var Menu = (function() { var burger = d ...

Error: No package.json file found after publishing npm package with ENOLOCAL

Ecosystem using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="335d435e73051d021d03">[email protected]</a> using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a8a9a2a386b0fee8f7f7e ...

Exploring File Read and Write Functionality in Angular 4

I want to develop an offline Task List in Angular 4. However, I am facing difficulty in finding a method to save data in a file on the client side using JavaScript or Angular. My current approach involves using browser's localStorage, but it is slow ...

Using AJAX to upload an image and passing multiple parameters

I'm facing an issue when trying to upload an image along with other input text in a form and send it to ajax_php_file.php. Whenever I upload the image, all my input text fields appear empty. Any assistance would be greatly appreciated. Thank you very ...

Is AJAX and jQuery support available on the iPhone?

Is iPhone compatible with AJAX and jQuery for support? I am working on creating a chatbox for the iPhone using these two technologies. Can they be used on MobileSafari? ...