0

I have this part of code:

if(mess <= 0 || mess < -width) {
img_container.find('ul').animate({'margin-left' : mess + 'px' }, 1000);
}

I need this to stop working when mess is lesser the -width. How can I do this?

3
  • 1
    Maybe if(mess <= 0 || mess < (width*-1) ) Commented Oct 16, 2012 at 13:30
  • What do you mean stop working? You do not want it to go into the if? Or do you want the animation to stop at some point? Commented Oct 16, 2012 at 13:31
  • @epascarello That is the intention. mess is always 0 or less, and when mess reach value which is lesser then width function needs to stop working. Commented Oct 16, 2012 at 13:34

3 Answers 3

6

See if you are getting width as string, if yes, use JS parseInt function.

If you are looking to stop animation syntax, see on http://api.jquery.com/stop/

It could be img_container.find('ul').stop();

This could help:

if(mess < (-1 * width)){
   img_container.find('ul').stop();
}
Sign up to request clarification or add additional context in comments.

2 Comments

Um, how is that any different to -width?
@raina77ow width is a number - width of all children elements.
1

You do not want it to do into the if the mess is less than the width?

You want to use AND instead of OR

if(mess <= 0 && mess > -width) {

Comments

1

You want the condition to fail if mess is less than -width, which means you only want it to succeed if mess >= -width.

Since it's a required condition just like mess <= 0, you need && instead of ||.

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.