function createPopup(text, element) {
$(element).magnificPopup({
items: [
{
src: `<span>${text}</span>`,
type: 'inline'
}
],
gallery: {
enabled: true
}
});
}
createPopup('Text', '.open-popup')
createPopup('Text2', '.open-popup2')
createPopup('Text3', '.open-popup3')
<button class="open-popup">Первая кнопка</button>
<button class="open-popup2">Вторая кнопка</button>
<button class="open-popup3">Третья кнопка</button>
$(document).on('click', '.open-popup', function(){
const data = [
{
src: '<span>Текст №1</span>',
type: 'inline'
},
{
src: '<span>Текст №2</span>',
type: 'inline'
},
{
src: '<span>Текст №3</span>',
type: 'inline'
},
]
$.magnificPopup.open({
callbacks: {
elementParse: function(item) {
item.src = data[item.index].src;
}
}
});
});