- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试将此 Popmotion
示例转换为 GreenSock
。
https://codepen.io/popmotion/pen/xVeWmm
var SELECTOR = '.box';
var velocityRange = [-1000, 1000];
var maxRotate = 30;
var smoothing = 100;
var box = ui.select(SELECTOR, {
values: {
x: 0,
y: 0,
rotateY: {
watch: function (actor) {
return actor.values.x.velocity;
},
mapFrom: velocityRange,
mapTo: [-maxRotate, maxRotate],
smooth: smoothing
},
rotateX: {
watch: function (actor) {
return actor.values.y.velocity;
},
mapFrom: velocityRange,
mapTo: [maxRotate, -maxRotate],
smooth: smoothing
}
}
});
var track2D = new ui.Track({
values: {
x: {},
y: {}
}
});
var springBack = new ui.Simulate({
simulate: 'spring',
spring: 500,
friction: 0.3,
values: {
x: 0,
y: 0
}
});
$('body').on('touchstart mousedown', SELECTOR, function (e) {
e.preventDefault();
box.start(track2D, e);
});
$('body').on('touchend mouseup', function () {
box.start(springBack);
});
作为 GreenSock
的菜鸟,这很容易做到吗? GreenSock
有 Actor 和模拟器吗?
最佳答案
我从来没有用过GreenSock
来制作连续的动态动画(也许有可能,我不是GreenSock
方面的专家)。我更喜欢离开这个库来制作特定的动画。在下一个示例中,我尝试使用我自己的计算复制您发布的相同 Popmotion
效果,我只是使用动画库将盒子返回到其原始位置。我认为它可以帮助您实现目标:
I've removed the vendor prefixes to make the code easier to read, but the
CodePen
example has the prefixes.
HTML 代码:
<div id="container">
<div class="box"></div>
</div>
CSS 代码
html {
height: 100%;
}
body {
background: #e25875;
height: 100%;
}
#container {
height: 100%;
perspective: 700;
perspective-origin: 50% 50%;
position: relative;
transform-style: preserve-3d;
width: 100%;
}
.box {
background: white;
border-radius: 4px;
height: 150px;
left: 50%;
margin-left: -75px;
margin-top: -75px;
position: absolute;
cursor: pointer;
top: 50%;
will-change: transform;
width: 150px;
}
JavaScript 代码:
//---Variables
var doc = document,
box = doc.querySelector(".box"),
startX = 0,
startY = 0,
posX = 0,
posY = 0,
speedX = 0,
speedY = 0,
obj = {x: 0, y: 0, speedX: 0, speedY: 0};
//---Main Events
box.addEventListener("mousedown", startMove);
doc.addEventListener("mouseup", stopMove);
//---Start the movement
function startMove (evt) {
startX = evt.pageX;
startY = evt.pageY;
//---Add the mouse move events
doc.addEventListener("mousemove", updatePosition);
}
//---Update variables
function updatePosition (evt) {
speedX = (evt.pageX - posX) * 5;
speedY = (evt.pageY - posY) * 5;
if (speedX < -45) { speedX = -45 }
if (speedX > 45) { speedX = 45 }
if (speedY < -45) { speedY = -45 }
if (speedY > 45) { speedY = 45 }
posX = evt.pageX;
posY = evt.pageY;
obj.x += (posX - startX - obj.x) * .15;
obj.y += (posY - startY - obj.y) * .15;
obj.speedX += (speedX - obj.speedX) * .15;
obj.speedY += (speedY - obj.speedY) * .15;
updateTransform();
}
//---Stop movement, returns the box to its place
function stopMove () {
TweenLite.to(obj, 0.75, {
ease: Elastic.easeOut.config(1, 0.3),
x: 0,
y: 0,
speedX: 0,
speedY: 0,
onUpdate: updateTransform
});
doc.removeEventListener("mousemove", updatePosition);
}
//---Update the box transformations
function updateTransform () {
var transformStr = "translate(" + obj.x + "px, " + obj.y + "px) rotateX(" + (-obj.speedY) + "deg) rotateY(" + obj.speedX + "deg)";
box.style.transform = transformStr;
}
这里有一个带有工作示例的 CodePen
。
编辑:我更新了 CodePen
以使用 Touch Events
。
关于javascript - 将 Popmotion 示例转换为 GreenSock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35401503/
我想知道如何在 GreenSock JavaScript 库中制作无限动画。我知道JavaScript当时只能进行1次操作,但我希望一些SVG图像能够不停地移动。对我来说,它看起来像无限循环,但我知道
我正在尝试对齐所有子补间的开始,希望它们立即开始,没有任何延迟,但似乎是按顺序完成的,一个 child 完成,然后第二个开始,第三个在第二个之后开始等等...不知道我在这里做错了什么? var tim
我正在尝试按以下顺序使用介绍文本和箭头制作介绍页面的动画: 背景图像来回移动两次。之后,箭头应从 1 缩放到 1.5,并再次重新缩放到原始大小 介绍文本也应缩放至 1.5 并重新缩放至其原始大小 由于
有一个 speed test在 greensock 网站上与其他动画库、JQuery 甚至 CSS Transitions 比较速度。它通过为数百/数千个分体设置动画来对 FPS 进行基准测试。 gr
我有以下代码: var mainTimeLine = new TimelineLite({paused:true}); var whiteGlow = "0px 0px 30px rgba(255,2
我想在 HTML 元素上一一添加类。 TweenMax.staggerTo(".some-class-name", 0.5, { className: "+=animation-class" }, 0
我以前从未使用过GreenSock。背景图像变化很好,它会切换和缩放,但是我面临的问题如下: Sprite 上显示的第一个背景图像不会缩放,但其他所有图像都会缩放,我该如何解决此问题? 它似乎会改变背
我正在尝试使用 Greensock 文本插件。我可以更改文本的颜色,但无法更改文本。我正在使用 jQuery 3.2.1 和 Greensock TweenMax 1.20.3 我的代码会将文本颜色更
我正在尝试使搜索栏具有动画效果。我能够在您单击时使其绘制,当您再次单击时它会返回到原始位置(使用 greensock - drawSVG)。 我希望能够在不刷新页面的情况下再次点击,并且一切正常。到目
我在鼠标事件上调用了两个函数: function menuBtnOver(e){ var b = e.data; b.setPosition(b.x, b.y+5); } functi
我正在尝试使用 JavaScript 和 Greensock 创建一个单击时滑入和滑出的导航栏。由于某种原因,当以不同尺寸单击时,单击操作随机不起作用,但有时它工作得很好。 我的代码如下,您可以在以下
我有一个正在使用 Greensock 的动画。当该动画完成并且用户单击按钮时,动画将反向播放。我遇到的问题是我希望动画反向播放的速度比最初播放时快 3 倍。我对如何做到这一点感到困惑。 我当前的代码工
我一直在使用javascript制作动画,但出现了我似乎无法解决的错误。 Link to Codepen Uncaught SyntaxError: Unexpected token '.' at
所以我正在尝试使用 Greensock 库为雪佛龙制作动画。我的目标是让 进入: 我在 Codepen https://www.codepen.io/Brushel/pen/boryZP 上有一个工作
我正在使用 GreenSock( https://greensock.com/get-started-js ) 进行动画。 问题是,当我向下滚动鼠标滚轮时,动画将从右向左工作。这不是一种权利。我需要当
我想将先前定义的 x/y 坐标数组传递给 greensock 贝塞尔曲线插件,如下所示: var ball = document.querySelector('#ball') var startCir
我正在尝试按照scrollmagic示例实现视差滚动。 greensock 文档说,像 TimelineMax.to 这样的东西定义了该场景中元素的最终位置(而不是定义初始位置的 .from)。 但是
我一直在尝试让动画在点击时触发,我已经通过 TimelineMax 创建了动画。我不明白为什么,但它一直触发这个动画的第一个实例,有 5 个 .blackout-panel 并且它为第一个 .blac
我正在尝试找到一种方法,将任意数量的元素添加到时间轴,然后在添加它们之后,同时开始运行它们。我尝试在添加到时间线之前调用 .pause() 并在之后播放,但它总是在我调用播放之前开始。 我目前正在运行
我正在嵌套时间线。 代码如下: timeLine.to(obj1,1.2,{css:{display:"block"}}) nestedTimeline1 = new TimelineMax({re
我是一名优秀的程序员,十分优秀!