Div blinking while resize

Etienne Arthur

I am working on a bootstrap based website and I have the following case : A main container and a floating left navigation menu. The floating left navigation menu, is set to position fixed, because it is following the user scroll.

problem description with the image What I would like is when the end user resize the window, and when the main content meets the left menu (overlap), the left menu becomes hidden, and when there is enough space the left menu comes back.

Actually, it is not really working, it is blinking. I have written a little bit of jquery binded to the resize function. Here is the jsfiddle :

https://jsfiddle.net/cuw46rsv/5/

function getDiffLeftMenu(div1, div2) {
    var value = ($(div1).offset().left - $(div2).offset().left);
    console.log(value  - $(div2).width());
    if(value - $(div2).width() < 0){
        return true;
    }
}

$(window).on('resize', function(event) {

    var value = ($('.central-content').offset().left - $('#sectionsMenu').offset().left);
    if(getDiffLeftMenu('.central-content','#sectionsMenu')){
        $('#sectionsMenu').hide();
    }
    else {
        $('#sectionsMenu').show();

    }
}).resize();

Is this possible to not have this blinking effet ? Thanks a lot for any help. Regards.

Slaven Tomac

Here's the solution with your logic, .hide() method causes it to have offset 0 and that's why it's blinking (it can get stuck as hidden all the time).

https://jsfiddle.net/cuw46rsv/7/

function getDiffLeftMenu(div1, div2) {
    var value = ($(div1).offset().left - $(div2).offset().left);
    console.log(value  - $(div2).width());
    if(value - $(div2).width() < 0){
        return true;
    }
}

By using opacity offset will stay there.

$(window).on('resize', function(event) {

        var value = ($('.central-content').offset().left - $('#sectionsMenu').offset().left);
        if(getDiffLeftMenu('.central-content','#sectionsMenu')){
            $('#sectionsMenu').css('opacity', 0);
        }
        else {
            $('#sectionsMenu').css('opacity', 1);

        }
    }).resize();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Blinking white cursor while booting

From Dev

jQuery clickable blinking text div

From Dev

Blinking issue of span with div hover

From Dev

JQuery How to resize div while scrolling top or down

From Dev

Android multiple notification avoid blinking while updating

From Dev

Page blinking while clicking on it | jQuery .load()

From Dev

Blinking of UIViewController while navigation from UICollectionViewController to UIViewController

From Dev

using while (!(cin ... and getting blinking prompt

From Dev

How to turn off blinking LED while suspend?

From Dev

Laptop battery indicator blinking red while green

From Dev

How to add blinking effect for the dynamically generated div

From Dev

CSS hide div on mouse hover but it is blinking

From Dev

Blinking div and mouseover/mouseout events and Prototype?

From Dev

angularjs - resize div on window resize

From Dev

Resize text in a div resize img

From Dev

angularjs - resize div on window resize

From Dev

Centering a Div on screen resize

From Dev

Resize textarea with div

From Dev

Automatically resize div tag

From Dev

Div resize into divs %

From Dev

Resize image to parent div

From Dev

Resize specific div

From Dev

Dynamically resize text in the div

From Dev

Resize div circle

From Dev

JQuery - resize div on click

From Dev

Java strange graphics blinking in while lock.await()

From Dev

Proportionally resize width and height of div on window resize

From Dev

Extjs:Resize panel with parent div resize

From Dev

resize div with image on page load and window resize