Change slider with linear-gradient on title

Hi, is it possible to change the background-color of the text of a slide while I move the mouse to the second one?
What I try to do is to use “linear-gradient”, below is the code I try to use:

$(‘.swiper-slide’).on(‘mouseenter’, function(e) {
var parentOffset = $(this).parent().offset();
var relX = e.pageX - parentOffset.left;
var perc = relX / $(this).width() * 100;
$(‘#title’).css(‘background’, ‘linear-gradient(to right, #005487 ‘+perc+’%, #ffffff ‘+perc+’%)’);
});

unfortunately I can’t change the color when I try to go back to the first slide, can anyone help me?

Thank you.