1

I have six buttons at the foot of my webpage, each with a hidden "popup" div that rises and fades in when you hover over the button. This functionality works, but because the buttons are close together you can often get two buttons overlapping when you switch hovering from one button to another very quickly.

I've tried to build some jQuery code to only allow the css 'rise and fade in' change to happen if all the other popups are below the bottom of the page. This will allow all the popups to reset before the currently-hovered button will raise its popup.

Unfortunately, the code is not working. None of the popups are now changing their css on hover.

This is the code from one particular button.

$('#chrome').hover(
            function () {

                if (
                $("#inuithoverpopup").css("bottom") < '-130%' &&
                $("#bloghoverpopup").css("bottom") < '-130%' &&
                $("#cchoverpopup").css("bottom") < '-130%' &&
                $("#cwlhoverpopup").css("bottom") < '-130%' &&
                $("#blhoverpopup").css("bottom") < '-130%' &&
                ) {
              $('#chromehoverpopup').animate({
                     opacity: '1',
                     bottom: '95%'
              }, 300);
            }

     },

     function () {
             $('#chromehoverpopup').animate({
                     opacity: '0',
                     bottom: '-159%'
             }, 300);

             });

Can anybody see what I'm doing wrong here?

1
  • 2
    You can't use the < operator on two string values and get a reliable result. You need to parse .css('bottom') to an integer, and compare it to an integer Commented Aug 5, 2016 at 7:48

1 Answer 1

3

Strings need to be converted to Number before attempting numerical logical operators on them.

try

parseInt($("#inuithoverpopup").css("bottom")) < -130

Note that the value returned will be in pixels and not % as you expected, so adjust value of 130% accordingly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.