How to disable select2 jQuery plugin on tablets?

I am using the Select2 jQuery plugin to improve the elements <select>in our project. However, on mobile devices (smartphones, tablets), Select2 actually impairs performance. In my opinion, the native elements of choice are better.

We are already detecting smartphones using regular expressions http://detectmobilebrowser.com/ , but they do not match the tables (and we would like to keep smartphones and tablets separately). Is there a link to regular expressions for the tablet like detectmobilebrowswer.com or another way to detect tablets?

+5
source share
2 answers
$(document).ready(function() {
    // run test on initial page load
    checkSize();

    // run test on resize of the window
    $(window).resize(checkSize);
});

function checkSize(){
  if (window.matchMedia("(min-width: 1024px)").matches) {
    $("select").select2();
  } else {
    $("select").select2("destroy");
  }
}
+2

, .

, Javascript PHP - .

,

-3

All Articles