hello everyone, sorry for my poor english first.
I want my project look like google art exhibition, so I use Vue and GSAP to make this demo
it work perfectly on pc, but something wired occured on mobile device (try codepen debug mode on your phone)
video of wired occured on mobile
the core code in codepen demo is initAnimation()
initAnimation(){
const vm = this;
const blockId = vm.blockData.blockId;
const tl = gsap.timeline({defaults:{ duration: 1}});
const $container = vm.$refs.container;
const $img = vm.$refs.image;
const posData = [];
vm.blockData.itemList.forEach(function(item){
let x = item.x;
let y = item.y;
posData.push({
x:`${x}%`,
y:`${y}%`,
scale: item.scale,
});
tl.add([
tl.to(`#immersive${blockId}-${item.itemId}`, { opacity: 1, y: "-10%" }),
tl.to(`#immersive${blockId}-${item.itemId}`, { opacity: 1, y: "-10%", duration: 5}),
tl.to(`#immersive${blockId}-${item.itemId}`, { opacity: 0, y: "10%" }),
])
})
// set text animation
ScrollTrigger.create({
animation: tl,
trigger: $container,
start: "top top",
end: `+=${vm.blockData.itemList.length * 1500}`,
scrub: true,
pin: true,
anticipatePin: 1,
// markers: true,
})
// set image animation
// delay to get real container height above
setTimeout(function(){
const realHeight = $container.parentNode.offsetHeight - $container.offsetHeight;
posData.forEach((pos,index)=>{
if(index === 0) return;
const thisFromTo = gsap.fromTo($img,posData[index-1],{...pos,duration: 1});
ScrollTrigger.create({
animation: thisFromTo,
trigger: $container.parentNode,
toggleActions: 'play none none reverse',
// set trigger point (according container height)
start: `${(index / posData.length)* realHeight}px`,
end: '+=20',
anticipatePin: 1,
// markers: true
})
})
gsap.set($img,posData[0]);
},500)
}
data structure of one block container look like this, here is all data
{
"blockId": 1044,
"itemList": [
{
"itemId": 3149,
"url": "https://images.unsplash.com/photo-1603486001734-7d92cedd1d33?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ",
"description": "lorem lorem lorem",
"x": -25,
"y": 3,
"scale": 1
},
{
"itemId": 5568,
"url": "https://images.unsplash.com/photo-1603486001734-7d92cedd1d33?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjE0NTg5fQ",
"description": "lorem2 lorem2 lorem2",
"x": 6,
"y": -12,
"scale": 1
}
]
},
I notice this situation seems only happened while having many scrollTrigger on page (or not)
and also occured when window.resize event fired (mobile address bar show/hide while scrolling)
Any suggestion to fix this, or better way to achieve this effect ? (google art exhibition)
Thanks you for reading here