Good day!
Found a script on the network to determine the screen size, but I can not figure out how to correctly set the definition isMobile, isTablet, isDesktop.
function() {
var i = {
mobile: "mobile",
tablet: "tablet",
desktop: "desktop",
oldHeight: null,
oldWidth: null,
current: function() {
return this.define()
},
isMobile: function() {
return this.define() === this.mobile
},
isTablet: function() {
return this.define() === this.tablet
},
isDesktop: function() {
return this.define() === this.desktop
},
define: function() {
return this.width() < 768 ? this.mobile : this.width() < 1360 ? this.tablet : this.desktop
},
height: function() {
return window.innerHeight
},
width: function() {
return window.innerWidth
},
init: function() {
this.oldHeight = window.innerHeight, this.oldWidth = this.define()
}
};
Tell me please...
Now I use this method:
if(
(screen.width <= 640) ||
(window.matchMedia &&
window.matchMedia('only screen and (max-width: 640px)').matches
)
){
// Do the mobile thing
}
But I think that the above script is more universal.
P.S. Can eat more correct ways of definition of the sizes of the screen?
Thank you