I would like to choose images depending on viewportWidth. Unfortunately I can't get it working. Only "else"-case ist showing, so the if function doesn't work. Can you help?
My code:
jQuery(document).ready(function ($) {
var viewportWidth = $(window).width();
if (768 < viewportWidth) {
$.backstretch("http://static.pexels.com/wp-content/uploads/2014/09/beach-sunset-traces-2730-527x350.jpg", {
duration: 3000,
fade: 750
});
} else if (1024 < viewportWidth) {
$.backstretch("http://static.pexels.com/wp-content/uploads/2014/09/beach-ocean-sea-2728-527x350.jpg", {
duration: 3000,
fade: 750
});
} else {
$.backstretch("http://static.pexels.com/wp-content/uploads/2014/09/boat-ocean-railing-2719-527x350.jpg", {
duration: 3000,
fade: 750
});
}
});
You can find it in a JSFiddle, too.