gpt4 book ai didi

jQuery 动画变换翻译 x,y

转载 作者:行者123 更新时间:2023-12-01 01:08:13 25 4
gpt4 key购买 nike

我需要为图像添加动画效果,但我想使用 CSS 转换。我发现之前的一个问题的解决方案是这样的:

jsFiddle

我这样修改:

jsFiddle

我不知道如何传递 x 和 y 值,因为我需要同时翻译 (x,y)。

这种方法行不通:

$('#box').animate({  fake: [100,50] }, {
step: function(now,fx) {
$(this).css('-webkit-transform','translate(' + now[0] + 'px,' + now[1] + 'px)');
},
duration:'slow'
},'linear');

最佳答案

;(function($) {
var delay = 0;
$.fn.translate3d = function(translations, speed, easing, complete) {
var opt = $.speed(speed, easing, complete);
opt.easing = opt.easing || 'ease';
translations = $.extend({x: 0, y: 0, z: 0}, translations);

return this.each(function() {
var $this = $(this);

$this.css({
transitionDuration: opt.duration + 'ms',
transitionTimingFunction: opt.easing,
transform: 'translate3d(' + translations.x + 'px, ' + translations.y + 'px, ' + translations.z + 'px)'
});

setTimeout(function() {
$this.css({
transitionDuration: '0s',
transitionTimingFunction: 'ease'
});

opt.complete();
}, opt.duration + (delay || 0));
});
};
})(jQuery);

这样你也可以使用translateZ;

来源http://cameronspear.com/blog/animating-translate3d-with-jquery/

关于jQuery 动画变换翻译 x,y,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15913941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com