I've fairly new to javascript
and jQuery
so help would be greatly appreciated.
I've designed a site from mobile up and used a slider to display a my block of image for small screens (< 500px).
The provided jQuery function
placed in the head works fine:
<script>
jQuery(function($) {
$('.slider').sss();
});
</script>
but works all the time.
I've found an example of javascript to write a script to the head based on the window width that works pretty well:
var script = document.createElement('script');
script.type="text/javascript";
if(window.matchMedia("(max-width:499px)").matches) {
jQuery(function($) {$(".slider").sss();});
}
document.getElementsByTagName('head')[0].appendChild(script);
But this doesn't respond to a changing window size. Once the function is loaded, it remains loaded and needs a manual refresh to either load or not load the function.
There must be a way to do this dynamically without having to refresh the page manually.