jeudi 2 février 2017

jQuery if width is less then.. change src attr, else, use the previous

(sorry for my bad english, I hope you understand) I would like that when the window width is less than 601px the src attribute of the image with .logo-wrap container became #; and when the width is larger the src attr returned as the "original"; The first part of the code works, but after I scale down the window and then carry it larger the src attribut remains #...

Any suggestions? thanks in advance

var $window = $(window);

function checkWidth() {
    var windowsize = $window.width();
    if (windowsize < 601) {
        $(".logo-wrap img").attr("src","#");
    }
    else {}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);   

Aucun commentaire:

Enregistrer un commentaire