Solved

Add px value to jquery css command

Posted on 2013-06-24
3
459 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 51

Expert Comment

by:Julian Hansen
Comment Utility
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 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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
Comment Utility
thanks yes that works..
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 41
Change month dropdown 5 15
Jump to a specific point on a responsive page 5 11
Problem to page 4 16
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

772 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

11 Experts available now in Live!

Get 1:1 Help Now