Highlight effect like Scriptaculous
Gives highlight effect for the elements.
Usage: params - el, start_color, end_color, duration (millis) [, restore_background_image]
Code:
HighlightEffect.highlight(field.el(), "FFD700", "EEE8AA", 2000);
Code:
public class HighlightEffect extends SingleStyleEffect {
private int[] base = new int[3];
private int[] delta = new int[3];
private String backgroundImage;
private boolean restoreBackgroundImage;
public static void highlight(El el, String from, String to, int duration) {
highlight(el, from, to, duration, true);
}
public static void highlight(El el, String from, String to, int duration, boolean restoreBackgroundImage) {
new Fx().run(duration, new HighlightEffect(el, from, to, restoreBackgroundImage));
}
protected HighlightEffect(El el, String from, String to, boolean restoreBackgroundImage) {
super(el);
this.restoreBackgroundImage = restoreBackgroundImage;
for (int i = 0; i < 3; i++) {
int b = Integer.parseInt(from.substring(i * 2, (i + 1) * 2), 16);
int e = Integer.parseInt(to.substring(i * 2, (i + 1) * 2), 16);
base[i] = b;
delta[i] = e - b;
}
}
@Override
public void onUpdate(double progress) {
StringBuilder sb = new StringBuilder(7).append("#");
for (int i = 0; i < 3; i++) {
String v = Integer.toHexString((int) (base[i] + delta[i] * progress));
sb.append((v.length() < 2) ? "0" : "").append(v);
}
el.setStyleAttribute("background-color", sb.toString());
}
@Override
public void onStart() {
this.backgroundImage = el.getStyleAttribute("background-image");
el.setStyleAttribute("background-image", "none");
}
@Override
public void onComplete() {
if (restoreBackgroundImage) {
el.setStyleAttribute("background-image", this.backgroundImage);
}
}
}