javascript - Variable after -= properties -


How do I insert a variable after jQuery's animate = properties?

  var slideObject = $ ('. Item'). Width (); $ ('Next'). ('Click', function () {event.preventDefault (); // View - = Slide Object $ (Slide Container). Animat ({margin lift: - = slide object}, 500);});  

Error in console:

Unkit syntax error: unexpected token - =

You are not using your event correctly:

  $ ('. Next'). ('Click', function event) {//      $ ('. Object') $ ('. Object'). Width (); $ ('. Next'). ('Click', function (event) {event.preventDefault (); $ (slideContainer) .net ({marginLeft:  

We .animate () The object is passed as a Object Lidral :

  var obj = {marginLeft: 200, // valid (number) margin right: "100" , // Valid (string) margin hat: top value, // valid (variable) marginbottom: "100px" // valid (string)}  

(Yes, you The above can be used as $ (slide kontata) iner) .animate (obj, 500); )

In the drawing:

  var obj = {marginLeft: - = 200, // unexpected token error margin right: "- = 100" // valid (string)}  

Therefore jQuery requires that a valid object is usually a string value like "200px"
allows us to use a number value to simplify our life Such as 200 px as default: "200px" .
This allows us to pass {marginLeft: margVal} as a code inside animate object, but - = margVal is no longer a valid object asset value, But unexpected token - = . If you convert your operator to a string with its variable, then "- = 200" will see a valid string.

Also keep in mind that if your slideContainer is already a jQuery object, then it again in jQuery in $ () .


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -