html5鼠标悬停图片文字3D视差动画特效
元素的HTML结构
- <a href="#" class="tilter tilter--2">
- <figure class="tilter__figure">
- <img class="tilter__image" src="img/3.jpg" alt="img03" />
- <div class="tilter__deco tilter__deco--shine"><div></div></div>
- <div class="tilter__deco tilter__deco--overlay"></div>
- <figcaption class="tilter__caption">
- <h3 class="tilter__title">Helen Portland</h3>
- <p class="tilter__description">Seattle</p>
- </figcaption>
- <svg class="tilter__deco tilter__deco--lines" viewBox="0 0 300 415">
- <path d="M20.5,20.5h260v375h-260V20.5z" />
- </svg>
- </figure>
- </a>
复制代码 元素的样式
- .tilter {
- position: relative;
- display: block;
- flex: none;
- width: 300px;
- height: 415px;
- margin: 1.5em 2.5em;
- color: #fff;
- perspective: 1000px;
- }
- .tilter * {
- pointer-events: none;
- }
- .tilter:hover,
- .tilter:focus {
- color: #fff;
- outline: none;
- }
- .tilter__figure,
- .tilter__image {
- display: block;
- width: 100%;
- height: 100%;
- margin: 0;
- }
- .tilter__figure > * {
- transform: translateZ(0px); /* Force correct stacking order */
- }
- .tilter__figure {
- position: relative;
- }
- .tilter__figure::before {
- content: '';
- position: absolute;
- top: 5%;
- left: 5%;
- width: 90%;
- height: 90%;
- box-shadow: 0 30px 20px rgba(35,32,39,0.5);
- }
- .tilter__deco {
- position: absolute;
- top: 0;
- left: 0;
- overflow: hidden;
- width: 100%;
- height: 100%;
- }
- .tilter__deco--overlay {
- background-image: linear-gradient(45deg, rgba(226, 60, 99, 0.4), rgba(145, 58, 252, 0.4), rgba(16, 11, 192, 0.4));
- }
- .tilter__deco--shine div {
- position: absolute;
- top: -50%;
- left: -50%;
- width: 200%;
- height: 200%;
- background-image: linear-gradient(45deg, rgba(0, 0, 0, 0.5) 0%, rgba(255, 255, 255, 0.25) 50%, transparent 100%);
- }
- .tilter__deco--lines {
- fill: none;
- stroke: #fff;
- stroke-width: 1.5px;
- }
- .tilter__caption {
- position: absolute;
- bottom: 0;
- width: 100%;
- padding: 4em;
- }
- .tilter__title {
- font-family: 'Abril Fatface', serif;
- font-size: 2.5em;
- font-weight: normal;
- line-height: 1;
- margin: 0;
- }
- .tilter__description {
- font-size: 0.85em;
- margin: 1em 0 0 0;
- letter-spacing: 0.15em;
- }
复制代码 JavaScript
在选项中,我们可以定义每个动画元素将具有的动作:
我们可以传递以下内容:所有轴和动画的平移和旋转(持续时间,缓动和弹性 - 与anime.js选项相同的方式)以恢复为默认样式。
对于平移和旋转,我们可以通过以下方式定义每个轴的值:
number :例如翻译:{X:10,Y:-10}意味着该元件将沿x轴从-10px从10px的移动为10px(我们着手从左至右的小鼠)和在y轴到-10px(当我们将鼠标从上到下移动时)。
array :如翻译:{Z:[10,100]}这意味着该元件将沿z轴从10px的移动到100像素(如我们从顶端移动鼠标到下)
- Initialize:
- new TiltFx(el, [options]);
- The options:
- var options = {
- movement: {
- // The main wrapper.
- imgWrapper : {
- translation : {x: 10, y: 10, z: 30},
- rotation : {x: 0, y: -10, z: 0},
- reverseAnimation : {duration : 200, easing : 'easeOutQuad'}
- },
- // The SVG lines element.
- lines : {
- translation : {x: 10, y: 10, z: [0,70]},
- rotation : {x: 0, y: 0, z: -2},
- reverseAnimation : {duration : 2000, easing : 'easeOutExpo'}
- },
- // The caption/text element.
- caption : {
- rotation : {x: 0, y: 0, z: 2},
- reverseAnimation : {duration : 200, easing : 'easeOutQuad'}
- },
- // The overlay element.
- overlay : {
- translation : {x: 10, y: -10, z: 0},
- rotation : {x: 0, y: 0, z: 2},
- reverseAnimation : {duration : 2000, easing : 'easeOutExpo'}
- },
- // The shine element.
- shine : {
- translation : {x: 100, y: 100, z: 0},
- reverseAnimation : {duration : 200, easing : 'easeOutQuad'}
- }
- }
- }
复制代码
|