"Subnav Menu Cascades Off the Screen Due to CSS Styling

I am facing an issue with my left-side vertical CSS menu where the subnavs pop out to the right. The problem arises when the last menu item has numerous subnavs that extend below the window fold.

I was wondering if there is a way, using either CSS or jQuery, to detect this beforehand and adjust the position accordingly so that all submenu items remain visible?

Check out the example at the following link (you may need to adjust the window height):

<!--demo is at following link-->

http://jsfiddle.net/otcq2ne0/

Answer №1

Check out this updated solution using the power of jQuery: http://jsfiddle.net/otcq2ne0/1/

$('body').on('mouseenter mouseover', '.vmdrop', function() {
    var subMenu = $('.vmenu-dropdown', this);

    if (subMenu.length) {
        var position = subMenu[0].getBoundingClientRect();
        if (position.bottom > window.innerHeight) {
            var threshold = position.top;
            var buffer = 10;
            var difference = window.innerHeight - (position.bottom + buffer);

            if (Math.abs(difference) > threshold) {
                difference = '-' + (threshold + buffer);
            }

            if (Math.abs(difference) > 0) {
                subMenu.css({ top: difference + 'px' });
            }
        }
    }
});

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

Creating a layout with Bootstrap 4 cards split into two rows

I need to change my layout from 3 columns to 2 columns. I know I can achieve this using CSS like the code snippet below, but I'm curious if there's a built-in Bootstrap method for this: .card-columns { -webkit-column-count: 2; -moz-column-co ...

Transmitting a PHP Bidimensional Array to JavaScript with Ajax

I am looking to send this PHP array to JavaScript using AJAX Here is the array contained in my main.php file: $entries = ldap_get_entries($ldap, $sr); for ($i=0; $i<$entries["count"]; $i++) { if (isset($entries[$i]["cn"][0])) { $ ...

Tally up the number of Dtrec_ID entries within the database

Can someone please explain how to count the occurrences of Dtrec_ID, for example counting how many times 1 appears and displaying it in the "Days Present" textbox? Click here to view the form. Click here to view the database. ...

Create a unique custom design for your Mapbox GL control

When developing the website, we utilized Angular 8, Typescript, and SCSS. We are using mgl-map to display a map, and I wanted to create a custom control for it with unique styles. I added the custom control to the map using: const centerOnCoordinatesC ...

Expand the video comparison slider to occupy the entire width and height

I am striving to develop a video comparison slider that fills the height and width of the viewport, inspired by the techniques discussed in this informative article: Article Despite my efforts, I have not been successful in achieving this effect so far a ...

Styling with Radial Gradients in CSS

Struggling to create a banner with a radial gradient background? I'm almost there, but my code isn't matching the design. Any assistance would be greatly appreciated as I can't seem to get the right colors and only part of the first circle i ...

The button's background color remains the same even after clicking on it

In my exploration of Vue.js, I decided to create a simple project to grasp the concept of class binding. I wanted to add functionality to each button component, so that when a button is clicked, it would change its color or background color to something ot ...

"Master the art of implementing a slide toggle effect with jQuery UI using

Looking to implement the jQuery UI slide toggle functionality in plain JavaScript... <center> <button id="button" class="myButton">Read More</button> </center> <div id="myDiv"> <p>Cool Read More Content Here. Lorem Ips ...

Choosing a Textbox within a form

I need help with the following concern: $("input:text").somefunction(); Is there a way to add a button and Textarea in the same code as above without relying on classes? ...

What could be causing my .load() function to fail when attempting to target a specific div element?

My goal is to retrieve and display a div tag from another aspx page within my container div. Here is the jQuery code: function GetDocumentInfo(url) { $('MyContainer').load(url + ".otherdiv"); } This operation is triggered by a click event. ...

Transfer files and data efficiently using Ajax

I am facing an issue while trying to send a file and data together to the Controller. When I only send the file, it works correctly. However, when attempting to send both data and a file, nothing seems to work. contentType: false, processData: false, Rem ...

The issue of background-attachment: fixed not functioning properly on Safari

Currently, I have the following code implemented on an element that extends 100% of the browser: #section_white { background-attachment:fixed; background-image:url(image_url_here.jpg); background-position:100% 100%; background-repeat:no-repeat no- ...

Div with Navigation Bar

Struggling to create a Nav Bar using Divs and aligning the links side by side? Looking for some guidance on how to achieve this design? Lorem Ipsum placeholder text added here. Lorem Ipsum ad usu quem delectus, sea stet sale id. Nulla nostrud appetere ea s ...

PHP MySQL Ajax modify data entry

I'm trying to implement a straightforward AJAX update function for records. Below is the code I have: index.php: <script type="text/javascript"> $("#submit_button").click( function() { $.post( $("#updateprofile").attr("action"), ...

Creating custom Magento extensions with jQuery integration

I am in the process of developing my very first extension that I plan to market on magento connect. One of the requirements for my module is jquery. The dilemma I face is if I include jquery in my module, it could potentially overwrite a version that the ...

The error message is stating that there is a TypeError because it cannot read the property "bind" of an undefined value when using the ng

When trying to implement the ng-cropper directive, an angular binding for the cropper javascript image cropping library, I'm encountering the error message TypeError: Cannot read property 'bind' of undefined. It seems to be related to the fo ...

Using an Ajax call with Spring MVC may result in receiving plain text instead of JSON

This is the AJAX call that I am using: $.ajax({ url: 'configuration/activePlatform/', type: 'GET', dataType: 'json', contentType: "application/json", success: function(data){ ...

Encountering a 403 error from AWS S3 bucket when trying to access a static folder path within a Django project

I have been successfully hosting static files in an S3 bucket for my Django web app using the Appwork custom admin template. The files render perfectly locally, but I am facing an issue with rendering from the S3 bucket. I suspect the problem lies in the s ...

The external javascript file is unable to recognize the HTML table rows that are dynamically inserted through an AJAX request

I have a situation where I'm pulling data from an SQL database and integrating it into my existing HTML table row. Here's the code snippet: Using Ajax to fetch data upon clicking analyze_submit: $(document).ready(function(e) { $('#anal ...

Sticky position applied and overlapping with the following container

I'm struggling with the CSS property position: sticky. In my layout, I have three boxes stacked one after another. Each box is styled with the class container from Bootstrap. The middle box, labeled as box-2, needs to be fixed in its position. To ach ...