下面是视差滚动的基础用法。
<template> <div class="t-parallax-scrolling-area"> <as-animation-parallax-scrolling :imgs="imgs" @scroll="scrollParallaxScrolling"> </as-animation-parallax-scrolling> </div> </template> <script> export default { name: "t-parallax-scrolling", data(){ return{ imgs:[ "https://images.pexels.com/photos/1097491/pexels-photo-1097491.jpeg", "https://images.pexels.com/photos/2437299/pexels-photo-2437299.jpeg", "https://images.pexels.com/photos/1005417/pexels-photo-1005417.jpeg" ] } }, methods:{ scrollParallaxScrolling(scrollTop,containerHeight){ let index=Math.ceil(scrollTop/containerHeight)+1; if (scrollTop%containerHeight<containerHeight/2){ index--; } console.log(`第${index}张图片占据主要位置`) } } } </script> <style> .t-parallax-scrolling-area{ width: 100%; height: 340px; } @media screen and (max-width: 480px) { .t-parallax-scrolling-area{ height: 180px; } } </style>
← 文字伸展 渐进式图片 →