dmstr / yii2-parallax
创建惊人的视差效果的扩展。
0.1.0
2018-08-29 12:48 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-13 02:03:57 UTC
README
创建惊人的视差效果的扩展。
安装
安装此扩展的首选方式是通过 Composer。
运行
composer require --prefer-dist dmstr/yii2-parallax "*"
或添加
"dmstr/yii2-parallax": "*"
到您的 composer.json
文件的 require 部分中。
使用方法
- 在视图中注册所需的资产包
- 设置 x 和 y 以定义方向和速度。一个额外的可选参数 (startCondition) 告诉元素何时开始移动。使用 "asap" 使元素在滚动事件触发时立即移动。对于那些在视口中变为可见时应该移动的元素,使用 "visible"(默认值)。
- 滚动以查看惊人的效果。
[data-parallax="{x}, {y}, {when}"]
具有 3 个视差元素的示例
<div data-parallax="0.2, -0.2, asap"></div> <div data-parallax="0.2, -0.2, visible"></div> <div data-parallax="0.2, -0.2"></div>
- 提示:尝试使用 CSS 过渡在 transform 上创建更棒的效果。
- 提示:为了制作逼真的视差效果,较近(或更大)的元素应该比较远的元素(或更小)移动得更快。
示例小部件使用
<?php Parallax::begin(['x' => 0.1, 'y' => -0.2, , 'startCondition' => 'visible']); ?> <?= '... some content' ?> <?php Parallax::end(); ?>