Is it possible to add media jquery's into your jquery code?
I need to reduce "slideWidth: 83," when my screen hits a size of 800px;
$(document).ready(function(){
$('.slider4').bxSlider({
slideWidth: 83,
minSlides: 2,
maxSlides: 9,
moveSlides: 1,
slideMargin: 15
});
});
}); Using this solution, regardless of how the browser treats the scrollbar, the jQuery and CSS media query will fire at exactly the same time. Baring in mind there are various wrappers and solutions that you could use, for something so small this was more than enough.
Using Media Queries With JavaScriptMedia queries are used to determine the width and height of a viewport to make web pages look good on all devices (desktops, laptops, tablets, phones, etc).
You may use as many media queries as you would like in a CSS file. Note that you may use the and operator to require multiple queries to be true, but you have to use the comma (,) as the or operator to separate groups of multiple queries. The not keyword can be used to alter the logic as well.
Media queries are supported in js via window.matchMedia
This allows you to create something like
var isPortrait = window.matchMedia("(orientation: portrait)");
if (isPortrait.matches){
// Screen is portrait
}
or
var smallScreen = window.matchMedia("(max-width: 480px)");
if (smallScreen.matches){
// Screen is less than 480px
}
Support is good within modern browsers and there is a polyfill available as well but it doesn't support resizing out of the box.
More info – https://developer.mozilla.org/en-US/docs/Web/API/Window.matchMedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With