Skip to content

Instantly share code, notes, and snippets.

@dan-zakirov
Last active April 8, 2024 09:29
Show Gist options
  • Save dan-zakirov/4b046211a30e6cd5125a98975cfe7bc0 to your computer and use it in GitHub Desktop.
Save dan-zakirov/4b046211a30e6cd5125a98975cfe7bc0 to your computer and use it in GitHub Desktop.
Тултипы при наведении на элементы с указанными классами, с учетом динамически добавленных элементов
/*
* Создаем тултипы при наведении на элементы с указанными классами, с учетом динамически добавленных элементов
*/
$(document).on('mouseenter', '.air_currency_auto, .data-air-video, .air-play', function () {
var title = $(this).attr('title');
$(this).data('title', title).removeAttr('title');
$('<div class="custom-tooltip-container"></div>').text(title).appendTo('body').fadeIn('slow')
.css({
'max-width': '240px',
'display': 'inline-block',
'background': '#fff',
'padding': '15px',
'border-radius': '10px',
'line-height': '16px',
'font-size': '13px',
'color': '#000',
'box-shadow': '0 0 10px rgb(28 39 76 / 20%)',
'z-index': '999',
'position': 'absolute'
});
});
/*
* Удаляем тултипы при выходе курсора мыши из элементов с указанными классами
*/
$(document).on('mouseleave', '.air_currency_auto, .data-air-video, .air-play', function () {
$(this).attr('title', $(this).data('title'));
$('.custom-tooltip-container').remove();
});
/*
* Позиционируем тултипы при движении мыши
*/
$(document).on('mousemove', function (e) {
$('.custom-tooltip-container').css({
top: e.pageY + 10,
left: e.pageX + 10
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment