После изучения событий и библиотеки tippyjs я обнаружил, что pointer-events: none
добавлено к элементу всплывающей подсказки, и кажется, что оно не позволяет нацеливать элементы, поэтому event.target
равно body
, но не ul
или li
.С https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
Свойство CSS-события указателя устанавливает, при каких обстоятельствах (если они есть) конкретный графический элемент может стать целью событий мыши.
Путем сбросаэто свойство через настройку pointer-events: initial
выводится предупреждение.Вот полный код:
$.ajax({
url: "https://jsonplaceholder.typicode.com/users",
success: function(json) {
var logoutpage = '<ul class="all-users-content">';
json.forEach((obj) => {
logoutpage += '<li>' + obj.name + '</li>';
});
logoutpage += '</ul>';
// actual tippy.js code
tippy('.logout-top-corner', {
content: logoutpage,
delay: 100,
arrow: true,
arrowType: 'round',
size: 'large',
duration: 500,
animation: 'scale',
trigger: 'click',
allowHTML: true,
hideOnClick: true,
// zIndex:9999999,
onShow: function() {
var refrence = document.querySelector('.logout-top-corner');
var tip = refrence._tippy;
var id = tip.id;
setTimeout(function() {
$('#tippy-' + id + ' .tippy-tooltip.dark-theme').css({
background: '#fff',
border: '1px solid #ccc'
});
$('#tippy-' + id + ' .tippy-roundarrow').css({
fill: '#eaeaed'
});
}, 200);
},
onShown: function() {
console.log($(this));
var refrence = document.querySelector('.logout-top-corner');
var tip = refrence._tippy;
var id = tip.id;
var el = document.getElementById('tippy-' + id);
el.style.cssText += 'pointer-events: initial';
$(document).off('click', '.all-users-content li');
$(document).on('click', '.all-users-content li', function() {
alert('clicked');
});
}
});
}
});
Если вы хотите удалить события указателя для всех элементов tippy, вы можете добавить код CSS:
*[id^='tippy-']{
pointer-events: initial;
}