Integrating tippy.js with swup #966
-
Describe your problem 🧐hello everyone! im trying to execute tippy.js and swup together in my astro website. tippy tooltip UI shows a gif played(like a preview) inside on hovering over its relevant links. this works fine on initial page view, but when we revisit the page, the UI is not shown whereas i get relevant console output. what can be the case here? what is that i need to modify the code? the same happens if i run swipper.js - where swipping of images works fine but it doesnt work on page revisit. import Swup from 'swup'
import SwupScriptsPlugin from '@swup/scripts-plugin'
import SwupA11yPlugin from '@swup/a11y-plugin'
import SwupHeadPlugin from '@swup/head-plugin'
import SwupSlideTheme from '@swup/slide-theme'
import SwupScrollPlugin from '@swup/scroll-plugin'
import SwupPreloadPlugin from '@swup/preload-plugin'
import SwupBodyClassPlugin from '@swup/body-class-plugin'
import SwupDebugPlugin from '@swup/debug-plugin'
import tippy from 'tippy.js'
import 'tippy.js/dist/tippy.css'
const swup = new Swup({
plugins: [
new SwupA11yPlugin(),
new SwupHeadPlugin(),
new SwupSlideTheme(),
new SwupScrollPlugin(),
new SwupPreloadPlugin(),
new SwupBodyClassPlugin(),
new SwupDebugPlugin()
],
animateHistoryBrowsing: true
})
function tippy_function() {
try {
tippy('.tippy_tip', {
arrow: true,
allowHTML: true,
hideOnClick: false,
offset: [0, 10],
placement: 'auto',
touch: true,
content: (reference) => {
const id = reference.getAttribute('data-template')
const template = document.getElementById(id)
return template.getElementsByTagName('img')[0]
}
})
console.log('found tippy tooltips')
} catch (error) {
console.log('no tippy tooltips')
}
console.log('leaving tippy_function')
}
function init() {
var mytippy = new tippy_function()
}
if (document.readyState === 'complete') {
init()
console.log('tippy initialised')
} else {
document.addEventListener('DOMContentLoaded', () => {
init(), console.log('tippy initialised')
})
}
swup.hooks.on('page:view', () => {
init()
console.log('tippy reloaded')
}) What is your question? 🙋♀️tippy.js UI shows on initial page loading and doesnt shows on page revisit. can someone help with what went wrong in my code? URL to minimal reproduction 🔗Checked all these? 📚
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
I'd recommend you create a minimal reproduction somewhere online that shows the issue. That way, it's super easy for others to jump in. Just from looking at the code, it seems correct, so the devil is in the details as always :) |
Beta Was this translation helpful? Give feedback.
-
@enlinquental you can wrap your code blocks on GitHub in three backticks to make it better readable. More information: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks |
Beta Was this translation helpful? Give feedback.
-
https://codesandbox.io/p/devbox/j85wvd uploaded my website here, please check, and let me know if you face any trouble to load. |
Beta Was this translation helpful? Give feedback.
-
You have installed the official astro integration of swup but then you have another initialization of swup in your main script (app_exp.js). That makes two swup instances working against each other. There are two ways to resolve this:
|
Beta Was this translation helpful? Give feedback.
You have installed the official astro integration of swup but then you have another initialization of swup in your main script (app_exp.js). That makes two swup instances working against each other.
There are two ways to resolve this:
globalInstance
set totrue
: https://github.com/swup/astro?tab=readme-ov-file#configglobalinstance – If you decide to go that route, make sure to remove theid="swup"
from your<main>
element, otherwise it might overwritewindow.swup