I'm getting value type error on my js script. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I'm getting value type error on my js script.

I'm trying an animation using the element.style.left=pos+"%" but it's not working. Please what should I do?

11th Apr 2020, 5:14 PM
xpan
xpan - avatar
22 Answers
+ 1
Your image has id "cont" but you use "box" in your js ^^
12th Apr 2020, 9:59 AM
visph
visph - avatar
+ 2
Relative units (%) are perfectly valid for positions (left, top, right, bottom) values... But positionning elements trough these properties requires a positioned element (with the css property 'position' as stated by luis calderón) but not necessarly 'absolute': any valid value appart 'static' (the default value for all elements). The main differences between 'absolute' and 'relative' position mode are: + 'absolute' doesn't keep the normal space needed by the element, while 'relative' keep it + 'absolute' coordinates (left, top, right, bottom) are relative to the whole document, while 'relative' coordinates are relative to the first positionned ancestor or to the whole document if none
11th Apr 2020, 9:05 PM
visph
visph - avatar
+ 1
Kk, thanks, I've tried most though
11th Apr 2020, 8:15 PM
xpan
xpan - avatar
13th Apr 2020, 7:31 AM
narayanaprasad
narayanaprasad - avatar
0
I positioned it well
12th Apr 2020, 9:24 AM
xpan
xpan - avatar
0
The error is on the line: element.style.left=pos+"%";
12th Apr 2020, 9:26 AM
xpan
xpan - avatar
0
... and the error message is???
12th Apr 2020, 9:35 AM
visph
visph - avatar
0
Value type error
12th Apr 2020, 9:36 AM
xpan
xpan - avatar
0
You must provide more context if you hope for help ^^ Share a code playground project link with your whole script (html/css/js), so we could investigate further ;)
12th Apr 2020, 9:40 AM
visph
visph - avatar
0
Kk I'd have shared but for the files are on my pc But I'll rewrite it.
12th Apr 2020, 9:46 AM
xpan
xpan - avatar
0
You could copy-paste from your pc to the website version of code playground: https://code.sololearn.com/
12th Apr 2020, 9:48 AM
visph
visph - avatar
0
Ooh, thanks
12th Apr 2020, 9:55 AM
xpan
xpan - avatar
0
https://code.sololearn.com/WlvItDzIT79w/?ref=app
12th Apr 2020, 9:56 AM
xpan
xpan - avatar
0
I'm starting to feel the error is because the element is an image
12th Apr 2020, 9:57 AM
xpan
xpan - avatar
0
I'm starting to feel the error is because the element is an image. Just copied the major parts into the code bit.
12th Apr 2020, 9:57 AM
xpan
xpan - avatar
0
The playground is giving the same error
12th Apr 2020, 9:58 AM
xpan
xpan - avatar
0
The playground is giving the same error
12th Apr 2020, 9:58 AM
xpan
xpan - avatar
0
I've corrected it, pls check
12th Apr 2020, 10:05 AM
xpan
xpan - avatar
0
well, it's working fine now :)
12th Apr 2020, 10:07 AM
visph
visph - avatar