I have this bit of code:
$({ speed: 0 }).animate({ speed: 500 }, {
duration: duration,
easing: 'easeInSine', // can be anything
step: function (now, fx) { // called on every step
var $current = $(self.settings.itemClass).first();
var left = parseInt($current.css("left"));
//console.log(now);
if (left <= distance) {
$current.hide(now, "linear", function () {
$(this).appendTo(self.settings.itemContainerClass).show(now, "linear");
});
}
},
complete: function () {
var $container = $(self.settings.itemContainerClass);
var $current = $(self.settings.itemClass).first();
var id = parseInt($current.attr("id"));
$.post("/Draw/SelectWinner/" + id, function (data) {
$container.delay(1000).hide("fast", function () {
var $name = $current.find("h3");
var $img = $current.find(".carousel-photo").find("img");
var $profileImage = ($img.attr("src") == "/img/transparent.png") ? "" : $img;
var twitter = ($current.find(".twitter").length > 0) ? $current.find(".twitter").text() : "";
var $winner = $('<div class="winner" />')
.css({
width: "100%",
height: "100%",
display: "none"
})
.addClass("red")
.appendTo(self.element)
.append("<div><h2>We have a winner!</h2></div>")
.append($name)
.append("<h4>" + twitter + "</h4>")
.append($profileImage)
.show("slow");
});
});
}
});
As you can see, I animate the speed from 0 to 500 using the easeInSine easing function. This works, but does not give me exactly what I want. What I want is to run this animation at a constant speed for 10 seconds and then gradually slow down until it stops for 5 seconds, but I have no idea how to write the easing function.
I know you can write your own easing functions by doing this:
$.easing.crazy = function(t, millisecondsSince, startValue, endValue, totalDuration) {
if(t<0.5) {
return t*4;
} else {
return -2*t + 3;
}
};
the part I need is to do something like
$.easing.crazy = function(t, millisecondsSince, startValue, endValue, totalDuration) {
if(t < 10) {
return 500;
} else {
// return a speed that gradually slows down
}
};
If anyone can help me work this out, I would be really greatful.
Update
Thanks to sparky, I have now managed to get this:
$.easing.wheel = function (x, t, b, c, d) {
return (t == d) ? b + c : c * (-Math.pow(2, -25 * t / d) + 1) + b;
}
but I still have an issue. This runs for 15 seconds but for the first few seconds it is nice and fast (I would say 3 seconds) and then for the rest it is slowly coming to a stop. I need it to run fast for 10 seconds and then for the last 5 slow down.
Does anyone know how I can modify the example to be better?
Cheers