简体   繁体   English

在FF / Chrome上使用jQuery在CSS3上进行矩阵转换的过渡

[英]CSS3 transition on matrix transformation with jQuery on FF/Chrome

I've written a simple little transition animation that on page load should reveal the content a little like the opening of a window blind. 我编写了一个简单的小过渡动画,页面加载后应该显示内容,就像打开百叶窗一样。 It uses a combination of css3, to set the transition values, and jQuery to apply a change to the transform: matrix values on page load. 它结合使用css3来设置过渡值,并使用jQuery将更改应用于转换:页面加载时的矩阵值。 It works fine in Safari, but for the life of me I can't grasp why the transition effect doesn't work on FF or Chrome. 它在Safari中可以正常工作,但是对于我来说,我无法理解为什么过渡效果在FF或Chrome上不起作用。 In both those browsers, the 'blind' just disappears to reveal the content after the transition display, rather than transitioning out in four vertical strips as it should. 在这两种浏览器中,“盲人”只是消失,以在过渡显示后显示内容,而不是按照应有的方式在四个垂直条中过渡。

Code below, I've also put this is a fiddle here (which, as I say works in Safari, so you can see the sort of effect I'm expecting): 在下面的代码中,我还在这里放了一个小提琴(正如我在Safari中所说的那样,所以您可以看到我期望的那种效果):

https://jsfiddle.net/ebenezer66/783uh6k3/ https://jsfiddle.net/ebenezer66/783uh6k3/

The basic html: 基本的html:

<div class="home__columnShades__div">
  <div class="home__columnShades__div__column">
    <div class="home__columnShades__div__columnOne"></div>
  </div>
  <div class="home__columnShades__div__column">
    <div class="home__columnShades__div__columnTwo"></div>
  </div>
  <div class="home__columnShades__div__column">
    <div class="home__columnShades__div__columnThree"></div>
  </div>
  <div class="home__columnShades__div__column">
    <div class="home__columnShades__div__columnFour"></div>
  </div>
</div>

SCSS: SCSS:

.home__columnShades__div {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  z-index: 899;
}

.home__columnShades__div__column {
  width: 25%;
  height: 100%;
  float: left;
}

.home__columnShades__div__columnOne {
  position: absolute;
  left: 0;
  height: 100%;
  width: inherit;
  background-color: #000;
  transition: transform 3s;
  transition-delay: 0.5s;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: top left;
}

.home__columnShades__div__columnTwo {
  @extend .home__columnShades__div__columnOne;
  left: 25%;
}

.home__columnShades__div__columnThree {
  @extend .home__columnShades__div__columnOne;
  left: 50%;
}

.home__columnShades__div__columnFour {
  @extend .home__columnShades__div__columnOne;
  left: 75%;
}

jQuery: jQuery的:

  var viewWidthQuarter = $(window).width() / 4;

  $('.home__columnShades__div__columnOne').css({
    'transform': 'matrix(0, 0, 0, 1, -' + viewWidthQuarter / 1.5 + ', 0)'
  });
  $('.home__columnShades__div__columnTwo').css({
    'background-position': '-' + viewWidthQuarter + 'px' + ' 0',
    'transform': 'matrix(0, 0, 0, 1, -' + viewWidthQuarter / 1.5 + ', 0)'
  });
  $('.home__columnShades__div__columnThree').css({
    'background-position': '-' + viewWidthQuarter * 2 + 'px' + ' 0',
    'transform': 'matrix(0, 0, 0, 1, -' + viewWidthQuarter / 1.5 + ', 0)'
  });
  $('.home__columnShades__div__columnFour').css({
    'background-position': '-' + viewWidthQuarter * 3 + 'px' + ' 0',
    'transform': 'matrix(0, 0, 0, 1, -' + viewWidthQuarter / 1.5 + ', 0)'
  });

Although I haven't solved why transform: matrix (or translate) won't work on FF/Chrome, I've reworked my code to use a transition on the left position of each vertical blind instead of transform's translate value. 尽管我还没有解决为什么transform:matrix(或translate)无法在FF / Chrome上运行的问题,但是我对代码进行了重新设计,以在每个垂直百叶窗的左侧位置使用一个过渡而不是transform的翻译值。 It actually even works a bit better - the animation is definitely smoother. 实际上,效果甚至更好一些-动画绝对更流畅。

https://jsfiddle.net/ebenezer66/ttgp8bj4/ https://jsfiddle.net/ebenezer66/ttgp8bj4/

Updated jQuery: 更新的jQuery:

  var viewWidth = $(window).width(),
  viewWidthQuarter = viewWidth / 4;

  $('.home__columnShades__div__columnOne').css({
    'left': viewWidth-(viewWidthQuarter*4.5) + 'px',
    'transform': 'scaleX(0)'
  });
  $('.home__columnShades__div__columnTwo').css({
    'background-position': '-' + viewWidthQuarter + 'px' + ' 0',
    'left': viewWidth-(viewWidthQuarter*3.5) + 'px',
    'transform': 'scaleX(0)'
  });
  $('.home__columnShades__div__columnThree').css({
    'background-position': '-' + viewWidthQuarter * 2 + 'px' + ' 0',
    'left': viewWidth-(viewWidthQuarter*2.5) + 'px',
    'transform': 'scaleX(0)'
  });
  $('.home__columnShades__div__columnFour').css({
    'background-position': '-' + viewWidthQuarter * 3 + 'px' + ' 0',
    'left': viewWidth-(viewWidthQuarter*1.5) + 'px',
    'transform': 'scaleX(0)'
  });

Updated CSS: 更新的CSS:

.home__columnShades__div {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  z-index: 899;
}

.home__columnShades__div__column {
  width: 25%;
  height: 100%;
  float: left;
}

.home__columnShades__div__columnOne {
  position: absolute;
  left: 0;
  height: 100%;
  width: inherit;
  background-color: #000;
  transition: transform 3s, left 3s;
  transition-delay: 0.5s;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: top left;
}

.home__columnShades__div__columnTwo {
  @extend .home__columnShades__div__columnOne;
  left: 25%;
}

.home__columnShades__div__columnThree {
  @extend .home__columnShades__div__columnOne;
  left: 50%;
}

.home__columnShades__div__columnFour {
  @extend .home__columnShades__div__columnOne;
  left: 75%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM