Parallax 视差

视差滚动是计算机图形学和网页设计中的一种技术,背景图像通过摄像机移动的速度比前景图像慢,在二维场景中创建一种深度错觉,并增加沉浸感。

QParallax 解决了很多问题,包括图像/视频的大小实际上可以小于窗口的宽度/高度。

QParallax API

QParallax API


speed
: Number
说明
视差效果的速度(0.0 < x < 1.0)
scroll-target
: Element | String
说明
用作自定义滚动容器的 CSS 选择器或 DOM 元素,而不是自动检测到的容器。

用法

滚动的容器

请阅读这里来了解 Quasar 如何确定要附加滚动事件的容器。

图像背景



<template>
  <div class="q-pa-md q-gutter-md">
    <div class="row justify-between">

    <q-parallax
      src="https://cdn.quasar.dev/img/parallax2.jpg"
    >
      <h1 class="text-white">Basic</h1>
    </q-parallax>

    </div>
  </div>
</template>

Basic

视频背景

WARNING

在某些 iOS 平台上,原生 <video> 标签的自动播放功能可能存在问题。参考。 QParallax 和 Quasar 不会以任何方式干扰客户端浏览器对 <video> 标签的能力/限制。

WARNING

当在 QParallax 中使用 video 标签时,您必须提供 widthheight 属性,以使 QParallax 正常工作,因为这种媒体具有固有的调整大小功能。 另外,请注意,只有在加载视频的元数据后,实际的视频宽度和高度才可用。



<template>
  <div class="q-pa-md">
    <q-parallax :height="150">
      <template v-slot:media>
        <video width="720" height="440" poster="https://cdn.quasar.dev/img/polina.jpg" autoplay loop muted>
          <source type="video/webm" src="https://cdn.quasar.dev/img/polina.webm">
          <source type="video/mp4" src="https://cdn.quasar.dev/img/polina.mp4">
        </video>
      </template>

      <h3 class="text-white">Video</h3>
    </q-parallax>
  </div>
</template>

Video

自定义速度



<template>
  <div class="q-pa-md">
    <q-parallax :height="200" :speed="0.5">
      <template v-slot:media>
        <img src="https://cdn.quasar.dev/img/parallax1.jpg">
      </template>

      <h1 class="text-white">Docks</h1>
    </q-parallax>
  </div>
</template>

Docks

使用插槽



<template>
  <div class="q-pa-md">
    <q-parallax>
      <template v-slot:media>
        <img src="https://cdn.quasar.dev/img/parallax2.jpg">
      </template>

      <template v-slot:content="scope">
        <div
          class="absolute column items-center"
          :style="{
            opacity: 0.45 + (1 - scope.percentScrolled) * 0.55,
            top: (scope.percentScrolled * 60) + '%',
            left: 0,
            right: 0
          }"
        >
          <img src="https://cdn.quasar.dev/logo-v2/svg/logo-mono-white.svg" style="width: 150px; height: 150px">
          <div class="text-h3 text-white text-center">Quasar Framework</div>
          <div class="text-h6 text-grey-3 text-center">
            v{{ $q.version }}
          </div>
        </div>
      </template>
    </q-parallax>
  </div>
</template>

Quasar Framework
v2.15.1