views:

64

answers:

1

Forgive me- I don't like adding to the beginner questions on here, but alas, I am stuck. I am trying to slide a bunch of things to the left and off the screen (including a background image), effectively toggling a control panel (#navCol) and making the main area bigger (.main to .mainLarge).

It's working ok in Firefox, but not in IE. I should note that I am beginner with jQuery, but not with html/css and the current css set up looks nasty but can't be avoided for this project. I suspect my jQuery is wrong, because in IE every time I hit the toggle link, only some of the animations occur. When clicked again, other ones do.

If I need to clarify anything, please let me know, and thanks in advance!

$('a#nav-toggle').click(function() {
  $('#navCol').toggle('slide',400);
  $('#main').toggleClass('mainLarge', 530);
  $('body').toggleClass('backgroundOffset', 500);
  return false;
});  

Is that right? Here is the html:

<body>
<div id="horNav">
<ul id="navigation">  
...
</ul> 
</div>
<div id="navCol">
Left Col
</div>
<div id="main" class="main"> 
Main Col
<a href="#" id="nav-toggle"><-></a>
</div> <!-- End main -->
</body>  

And here's the css:

body {
    background: #f1f1f1 url(/images/shadow.png) repeat-y top;
    background-position: 400px 0px;
}

.backgroundOffset{
    background-position: 55px 0px;
}

#navCol{
    background: #eaeaea;
    color: #000000;
    height:100%;
    left:0px;
    margin-right:40px;
    position:fixed;
    top:0;
    width:400px;
    padding-top: 70px;
}

.main{
    padding-left: 460px;
    padding-top: 100px;
    padding-right: 100px;
}

.mainLarge{
    background-position: 55px 75px;
    padding-left: 115px;
}
+1  A: 

What version of jQuery are you using? Those methods don't look like they have the right parameters for jQuery 1.3+. I would think it would be more like:

$('a#nav-toggle').click(function() { 
  $('#navCol').slideToggle(400);
  $('#main').toggleClass('mainLarge'); 
  $('body').toggleClass('backgroundOffset'); 
  return false; 
});

You can't supply a speed for the class toggle -- it either has the class or not. The standard second argument is a flag indicating the current whether the new value should on or off.

tvanfosson
Interesting, because the speed seems to affect the toggle in Firefox. But thank you for the tip! So to slide the elements, I should spell it out in jQuery, and not try to do it with classes?
James M
By slide I mean animate, not just snap.
James M
Yes,if you want them to actually slide to a particular position, you'd need to use the animate function and specify where you want them to end up.
tvanfosson