Solved

Add px value to jquery css command

Posted on 2013-06-24
3
460 Views
Last Modified: 2013-06-24
Hi,

I am trying to add variables to the transform command in CSS with jquery but it doesnt work, any ideas?

My code is

 $x = $(this).attr("cx")+'px';
 $y = $(this).attr("cy")+'px';
      $(this).css('transform', "translate($x,$y) scale(2)"); });

$x and $y do get values.

Thanks
0
Comment
Question by:coolispaul
3 Comments
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 39270901
You are putting '$' in front of your vars - this is JQuery not PHP

Try this

var x = $(this).attr("cx")+'px';
var y = $(this).attr("cy")+'px';
$(this).css('transform', "translate(x,y) scale(2)"); });
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39271291
jQuery doesn't replace variables in strings the same way that PHP does. You need to concatenate the translate argument properly:

$x = $(this).attr("cx")+'px';
$y = $(this).attr("cy")+'px';
$(this).css('transform', "translate(" + $x + "," + $y + ") scale(2)");

Open in new window

The $ before the variable name is OK, although not very common!
0
 

Author Comment

by:coolispaul
ID: 39271482
thanks yes that works..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add animation to your css 12 32
WordPress Themes 10 34
Error in script 11 43
Angular - "nest" service calls? 18 20
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now