Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic X axis

ANSWERED

Hopefully an easy one...

 

How do I assign a percentage value to the var.x value?  I can assign it a number (pixel):

myVar.x = 100;

I have yet to crack how to assign a percentage like I do in the .css.  Both of these fail:

myVar.x = 40%;
myVar.x = "40%";

What am I missing here?

 

Thanks.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Sorry, the percentage values aren't currently supported, but you can calculate the pixel value from the device screen dimensions.

 

 

import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };

let percent = 40;
let pixels = percent / 100 * device.screen.width;
myVar.x = pixels;

 

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

Sorry, the percentage values aren't currently supported, but you can calculate the pixel value from the device screen dimensions.

 

 

import { me as device } from "device";
if (!device.screen) device.screen = { width: 348, height: 250 };

let percent = 40;
let pixels = percent / 100 * device.screen.width;
myVar.x = pixels;

 

Best Answer
0 Votes

Thanks JohnFitbit.  I am doing something similar to your solution, but I was hoping there might be a cleaner/simpler way of doing it.

 

Jeff

Best Answer
0 Votes