admin管理员组文章数量:1405102
Please refer below animation code.
$(element).delay(2000).animate({
scale: 1,
}, {
duration: 1000,
step: function (now) {
scaleVal = now;
$(element).attr("transform", "translate(" + centerX + " " + centerY + ") scale(" + scaleVal + ") translate(" + (-centerX) + " " + (-centerY) + ")");
}
});
scale is attribute of an element. scale value always starts from 0 and end up in 1. i want scale value starts from 0.5 and goes up to 1.
In step function scale always starts from 0.
Need : scale value maximum is 1 and starts from 0.5 instead of 0.
Thanks,
Siva
Please refer below animation code.
$(element).delay(2000).animate({
scale: 1,
}, {
duration: 1000,
step: function (now) {
scaleVal = now;
$(element).attr("transform", "translate(" + centerX + " " + centerY + ") scale(" + scaleVal + ") translate(" + (-centerX) + " " + (-centerY) + ")");
}
});
scale is attribute of an element. scale value always starts from 0 and end up in 1. i want scale value starts from 0.5 and goes up to 1.
In step function scale always starts from 0.
Need : scale value maximum is 1 and starts from 0.5 instead of 0.
Thanks,
Siva
Share Improve this question edited Jun 11, 2013 at 7:25 palaѕн 74k17 gold badges122 silver badges139 bronze badges asked Jun 11, 2013 at 7:17 SivaRajiniSivaRajini 7,37522 gold badges84 silver badges129 bronze badges 2- possible duplicate of jquery animate function initialize the value – elclanrs Commented Jun 11, 2013 at 7:18
- @eclanrs: there is no solution provided in that link.am using attribute not a css of an element. – SivaRajini Commented Jun 11, 2013 at 7:23
2 Answers
Reset to default 4jQuery use Tween.propHooks
to get/set properties in animation. The non-CSS property scale
will be treated as a property binded to the DOM element that is being animated on. So you can set the initial value of the scale
property before animation.
$(element).each(function () { this.scale = 0.5; }).delay(2000).animate({
scale: 1,
}, {
duration: 1000,
step: function (now) {
scaleVal = now;
$(element).attr("transform", "translate(" + centerX + " " + centerY + ") scale(" + scaleVal + ") translate(" + (-centerX) + " " + (-centerY) + ")");
}
});
Live Demo
You may also use second argument of the step function, which is a reference to the jQuery.fx object. Among other it has "start" property that specifies first value of the animated property (it also has 'end' for the last value and 'prop' to specify property being animated)
Also you should set css transform of the animated element to be 0.5 at the beginning, so that it won't be set from 0 to 0.5 abruptly when animation starts, and you should use .css method to do this, not .attr, as its not element's attribute, but css3 property.
$(element).css("transform","scale(0.5)").delay(2000).animate({
scale: 1,
}, {
duration: 1000,
step: function (now, fx) {
scaleVal = now;
fx.start = 0.5;
$(element).css("transform", "scale(" + scaleVal + ")");
}
});
see jsfiddle
also, when you use "translate" method for css transformation, you should set ma between x and y values
translate(" + centerX + ", " + centerY + ")
本文标签: javascriptjquery animate step function with attribute value initializationStack Overflow
版权声明:本文标题:javascript - jquery animate step function with attribute value initialization - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744890877a2630772.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论