javascript - JS "@media" device resolution change property of js command -


i'm doing responsivity on website in js. how can change (normal resolution):

$(".card1_content_arrow").click(function () {     $(".card1_content").css('margin-left', '-45%'); }); 

into this, when media width <860px (in css @media , (max-width: 860px)):

$(".card1_content_arrow").click(function () {     $(".card1_content").css('margin-left', '-100%'); }); 

when click on .card1_content_arrow on big resolution, margin-left changed -45%', if change resolution 860px (and less) want, when click on same .card1_content_arrow, margin-left changed -100%. :)

you can detect screen resolution described on question.

$(".card1_content_arrow").click(function () {     var margin = "-45%";      if (window.screen.availwidth < 860) {         margin = "-100%";     }      $(".card1_content").css('margin-left', margin); });  

i suggest using media queries instead specifying class control margin.

.yourclass {     margin-left: -45%; }  @media (max-width: 859px) {     .yourclass {         margin-left: -100%;     } } 

you can add class element , let browser checking.

$(".card1_content_arrow").click(function () {     $(".card1_content").addclass('yourclass'); }); 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -