T
T
t00rt2017-04-14 02:28:26
css
t00rt, 2017-04-14 02:28:26

How to get CSS block margin as a percentage using jquery?

There is a slider block for which margin is not initially set, I get the margin value:

var currentMargin= $(".slider").css("marginLeft"); // The value comes in pixels - "0px". Next, the resulting value is truncated, reduced to a number, -100 is subtracted, and the % sign is added.

Then I set the shift value as a percentage:
$(".slider").css("margin-left" , currentMargin); // Thus, the picture is shifted to the left by -100%, everything is fine.

However, when I try to get the margin value again, for another shift of -100% and show the next slide, it comes again in pixels, although it is already set in% i.e. at different screen resolutions, a different value in pixels is obtained, which is not good.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
suberg, 2018-04-10
@FreeMan94

Gradient variant: https://codepen.io/suberg/pen/RMvdew

F
forspamonly2, 2018-04-10
@forspamonly2

this light green is probably just white with translucency? and on a white background it is not visible

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question