I have a grid that contains two rows and three columns. Each column has a picture, a title, and a subtitle. All the pictures have the same class, let's say "image".I want the picture to change during hover. I have a div with the other image (the one that I want to show on hover) with the property display: none;
This is the HTML code:
<div class="row-1">
<div class="col-1">
<div class="view-field-image">
<div class="field-content">
<img class="image" src="../.." al="">
</div>
</div>
<div class="view-field-collapsed">
<div class="field-content">
<img class="collapsed" src="../.." al="">
</div>
</div>
</div>
<div class="col-2">
</div>
<div class="col-3">
</div>
</div>
This is the js code:
(function ($, Drupal) {
'use strict';
Drupal.behaviors.hoverEffect = {
attach: function (context, settings) {
$('.view-field-image .field-content', context)
.once()
.each( function () {
$(this, context)
.mouseenter( function () {
console.log('enter');
$('image', context).css('display', 'none');
$('.collapsed', context).css('display', 'block');
})
.mouseleave( function () {
console.log('leave');
$('image', context).css('display', 'block');
$('.collapsed', context).css('display', 'none');
});
});
}
};
})(jQuery, Drupal);
I don't have the excepted result. When I hover over the picture all the pictures show the hidden picture with the collapsed class. Furthermore the picture with the class= "image" doesn't disappear.