0

I want to change my animations using jQuery and found this helpful tutorial. This works -

 $.keyframe.define([{
     name: 'slidein',
           
        from:   {'margin-left': '100%'},
        to:   {'margin-left': '10%'}
       }]);

But instead of providing a fixed percentage or px value, I want to use a variable which has a px or percentage value stored in it. I have tried all the below and none worked

   // to:   {'margin-left': bigSlide.width}
   // to:   {'margin-left': 'bigSlide.width'}
   // to:   {'margin-left': calc(bigSlide.width)}
   // to:   {'margin-left': 'calc(bigSlide.width)'}
   // to:   {'margin-left': (100px+630px)}
   // to:   {'margin-left': calc(100px+630px)},
   // to:   {'margin-left':'calc(100vw - 800px)'}

}]);

I tried options such as calc(100px+630px) to just see if I could get calc working.

3 Answers 3

1

You need to add a value in the form - to: {'margin-left': bigSlide.width + 'px'}. Use concatenation.

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

Try wrapping your variable in a template literal like this:

\`${variableName}\` 

This will make it read as a string with whatever value is in the variable.

Comments

0

Thank you Maxim G for your above suggestion. I got this solution working.

$.keyframe.define([{
      name: 'slidein',
    
      from:   {'margin-left': '100%'},
      to:   {'margin-left':bigSlide.width + bigSlide.getBoundingClientRect().left+'px'}

    }])

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.