I'm trying to do some stuff with jQuery and the action is going too slow.
I have an embed (pinterest layout like) collection (pure CSS) in an iOS UIWebView, each pin have a button and this button sends a love over the action. When the user touch the button i have to send the love (unlove) to the server and also refresh the UI (more precisely change a background image).
The problem is that since the user press the button, i'm having almost a second of delay (before the background image change). I will try to avoid this using setTimeout function "emulate" a secondary thread. But didn't work as expect.
What i tried exactly was:
setTimeout(function() {
love_btn.css("background-image", "url(btn_like_black@2x.png)");
pin.find(".love").css("background-image", "url(img_like@2x.png)");
var x = parseInt(pin.find(".counter").first().text());
var u = x - 1;
pin.find(".counter").first().text(u);
}, 0);
window.location.href = "protocol://unlove/" + love_id;
Last line is a redirection handled in objective-c code to call the WebService that register the love (unlove).
By the way, i tried the timeout in the server call too. So, the question is: Is there a way to change this background images as soon as posible using jQuery? is the setTimeout function worling is really working as i think?
Thanks.