jquery - If element translate 3d ... addClass -
how can write script this?
if div class "test" has property translate3d (0px, 100px, 0px)
add "active" class else remove it.
i tried it's not right ...
setinterval(function(){ if($('.test').css('transform') == 'translate3d(0px, 100px, 0px)') { $('.test').addclass('active'); } else { $('.test').removeclass('active'); } }, 1);
you need below using regex match:-
$(document).ready(function(){ $('.test').each(function(){ console.log($(this).css('transform') == 'matrix(1, 0, 0, 1, 0, 100)'); if($(this).css('transform') == "matrix(1, 0, 0, 1, 0, 100)"){ $(this).addclass('active'); } else { $(this).removeclass('active'); } }); });
.active { color: red; font-size: 20px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="test" style="transform:translate3d(0px, 100px, 0px)">hello</div><br/><br/> <div class="test" style="transform:translate3d(10px, 10px, 100px)">hello</div>
note:- check console.log()
value , see it's matrix
reference taken:- get translate3d values of div?
to check element have transform property or not use below regex:-
/matrix(?:(3d)\(\d+(?:, \d+)*(?:, (\d+))(?:, (\d+))(?:, (\d+)), \d+\)|\(\d+(?:, \d+)*(?:, (\d+))(?:, (\d+))\))/)
Comments
Post a Comment