I have a slide-out div, absolutely positioned in a relatively positioned parent, which moves nearly off the left side of the screen upon the click of a button.
I’m animate() -ing the css left property to move it. It looks fine until you resize the window. Upon resize, the div is then either too far into the page or too far outside of the page (depending on if you are enlarging or shrinking the window).
How can I keep the div flush with the page upon resize?
Basically I want the right side of the div to always be 15px from the window border when the div is “slid out”.
I was able to replicate the problem on Codepen, but not jsFiddle:
Thanks! It even handled the min-width case. Would you recommend just using addClass() along with CSS transitions? I haven’t gotten to test this out on my project yet but will get back on if it works soon.
And would be even easier if you did not need a `min-width` : [http://codepen.io/georgearnall/pen/cHBAx](http://codepen.io/georgearnall/pen/cHBAx “http://codepen.io/georgearnall/pen/cHBAx”)
Plus, by changing `addClass` to `toggleClass` you could easily have this box hide and unhide from view.
The only thing to mention about CSS transitions is browser computability but you should ask yourself wether animated transitions are just a nice touch or a key part of your design.
Thanks so much! Yes this was really really helpful, and that was great code. Many kudos!
Yeah, as you may have read I’ve been doing a few client sites for practise ( + money :P ) and have only just recently started using these forums to help people. I haven’t really done much in the way of learning jQuery myself. I basically just learn it as I need it but generally all I ever use it for is toggling classes.
For the time being, I am definitely going to continue doing this because its fun! Plus, it does help me afford things :)
Oh nice! Yeah that is the best way to go about it. It’s great that you’re getting paid while building up a portfolio. I tried to do some volunteer web design and I spent wayy too much effort and time into it, however it did get me a job which I’m thankful for.
All that being said though, I think the most important thing is that it’s fun and stays fun. Don’t ever let it become a “job” (even if it is a job), or anything so that it is no longer fun. I’m not that experienced either, but that’s my opinion so far at least!