0

Is there a way to return a CSS element?

I was using Adobe Edge and adding some of my own code in their code tab, but in order to create boundaries I would need to keep track of margin-top or margin-left. The following code works to move the element "woo" but I'm not sure how to call the elements to add something like "|| sym.$("woo").css({"margin-left">0px"}) to the move left code.

//Move RIGHT
if (e.which == 39) {
   sym.$("woo").css({"margin-left":"+=10px"});
}
//Move UP
else if (e.which == 38) {
    sym.$("woo").css({"margin-top":"-=10px"});
}
//Move Left
else if (e.which == 37) {
    sym.$("woo").css({"margin-left":"-=10px"});
}
//Move DOWN
else if (e.which == 40) {
    sym.$("woo").css({"margin-top":"+=10px"});
}

EDIT:

I changed the Left if statement to the following:

else if (e.which == 37 && ($("woo").css("margin-left")>0)) {

It seems to be working to some extent except for now it won't move left at all! I tried doing <0 too in case I was screwing up a sign but it won't let me move the element left either.

ANSWER:

Well it turns out that the syntax of returning values is a little different than i thought. To return the left margin instead of using the dash like how i used to set it, I had to do as below.

sym.$("woo").css('marginLeft')

And then to actual make it an int and compare it I used this.

if(parseInt(sym.$("woo").css('marginTop'))>0)
Charles
  • 50,943
  • 13
  • 104
  • 142
Tom Prats
  • 7,364
  • 9
  • 47
  • 77

2 Answers2

1

You can get the value of a CSS property by calling the .css() method:

$(...).css('margin-left')
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

Well it turns out that the syntax of returning values is a little different than i thought. To return the left margin instead of using the dash like how i used to set it, I had to do as below.

sym.$("woo").css('marginLeft')

And then to actual make it an int and compare it I used this.

if(parseInt(sym.$("woo").css('marginTop'))>0)
Tom Prats
  • 7,364
  • 9
  • 47
  • 77