根据现场示例进行编辑
试试这个演示
您可以WebKitCSSMatrix
在您的情况下使用来获取translate3d
值。我不知道它的所有选择器,但是e
isx
和f
is y
,所以这段代码有效,因为你不改变z
var words = document.getElementById("words");
var speed = 10;
words.style.webkitTransform = "translate3d(0px, -"+(27 * (words.children.length))+"px, 0px)";
words.style.webkitTransition = ((27 * words.children.length)/speed)+"s all linear";
var paused = false;
document.getElementById("button").onclick = function() {
if(!paused) {
var translated3D = new WebKitCSSMatrix(window.getComputedStyle(words, null).webkitTransform);
words.style.webkitTransform = "translate3d(" + translated3D.e + "px, " + translated3D.f + "px, " + 0 + "px)";
paused = true;
button.innerHTML = "Start";
} else {
paused = false;
button.innerHTML = "Stop";
words.style.webkitTransform = "translate3d(0px, -"+(27 * (words.children.length))+"px, 0px)";
words.style.webkitTransition = ((27 * words.children.length)/speed)+"s all linear";
}
}
话虽这么说,我会避免transform3d
一些这样简单的事情,但它会使问题复杂化。