0

I am using Jquery UI with the addClass/removeClass function. It is changing the class, but without the duration. Here is my code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>    
<script src="jquery-ui-1.8.24.custom.min.js" type="text/javascript"></script>
<!--This has the Effects Core and all four boxes checked in the UI Core-->
<style type="text/css">    
.menu {
    height: 35px;
    padding: 15px 20px 5px 20px;
    font-family: 'Open Sans Condensed', sans-serif;
    font-size: 1.3em;
    font-weight: bold;
    display: inline;
    float: right;
    background: none;
}
.menu-hover {
    height: 35px;
    padding: 15px 20px 5px 20px;
    font-family: 'Open Sans Condensed', sans-serif;
    font-size: 1.3em;
    font-weight: bold;
    display: inline;
    float: right;
    background: url(../img/header-bg2.png) repeat-x;
}
</style>
<script>
  $(document).ready(function() {
    $('.menu').hover(function() {
      $(this).addClass("menu-hover", 1000);
    }, function() {
      $(this).removeClass("menu-hover", 1000);
    });
  });
</script>

<a href="#"><div class="menu">Contact</div></a>
<a href="#"><div class="menu">Services</div></a>
<a href="#"><div class="menu">About</div></a>
<a href="index.html"><div class="menu">Home</div></a>

I have double-checked to make sure that it is indeed changing the class, and it is. Any ideas how to get the duration to work? Thanks.

11
  • Why do you want to add a duration? If you really want a "duration", do you mean delay()? Commented Oct 18, 2012 at 3:36
  • There's no duration parameter in both addClass and removeClass methods. Commented Oct 18, 2012 at 3:37
  • I am trying to do this. Commented Oct 18, 2012 at 3:37
  • 3
    This is jQuery UI, not plain jQuery. api.jqueryui.com/addClass Commented Oct 18, 2012 at 3:38
  • Don't listen to these guys... JqueryUI has a method override of jQuery's built in addClass Commented Oct 18, 2012 at 3:38

2 Answers 2

1

Jquery UI will animate background colors, but not background images.

Source: Trial and error.

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

1 Comment

Makes sense, how could you logically animate between binary image data?
0

For the delay, you can use jQuery's delay():

$('.menu').hover(function() {
  $(this).delay(1000).addClass("menu-hover");
}, function() {
  $(this).delay(1000).removeClass("menu-hover");
});

3 Comments

@BrianVanderbusch I don't get you!
@preahkumpii What does it mean? Please update your question and give a comment here. :)
OKay, @preahkumpii Please update it in the question. And I have given you a suggestion using delay(). Will that work for you?

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.