jquery - Image switch with data-attribute -
$(window).scroll(function() { var scroll = $(window).scrolltop(); if (scroll >= 50) { $("header").addclass("sticky"); $('header .logo img').attr('src', $('header .logo img').data("hover")); } else { $("header").removeclass("sticky"); $("header").addclass(""); $('header .logo img').attr('src', $('header .logo img').data("src")); } }); the first 1 works src not coming anymore. how should done?
<img src="img/logo2.png" data-hover="img/logo.png" alt="" class="img-responsive" />
you should add data-src attribute try access.
<img src="img/logo2.png" data-src="img/logo2.png" data-hover="img/logo.png" alt="" class="img-responsive" />
Comments
Post a Comment