Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - use css in if statement argument

I'm using vw for previous divs, now I want to set an alert if a div is moved to the very left. Here's the div:

<div id='pagination'>some stuff</div>

Now its width is set to 84vw, which was calculated from early functions. I want to alert when its margin-left equals -84vw. I tried this in js but no luck:

if ($('#pagination').css('margin-left') == '-84vw') {
    alert('you're good to go!');
}

Could anyone help me with this argument? The real headache is I can't change vw to px.

like image 759
Jasmin_W Avatar asked Mar 13 '23 10:03

Jasmin_W


1 Answers

For Conversion of px and vw refer this

1px = (100 / document.documentElement.clientWidth)vw

e.g. — If your viewport was 500px wide (equals by definition to 100vw) then

1px = (100 / 500) = 0.2vw

Plus you had a syntax error ..Please handle the quotes properly

alert('you\'re good to go!');
like image 157
Amar Singh Avatar answered Mar 23 '23 05:03

Amar Singh