Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Sunday, March 17, 2013

How to pause execution of javascript for sometime

Today, I was just looking into the ways to pause or wait or delay execution of my javascript statement for some given time. I do some google for this and I got such a really good code snippet - sleep() function from somewhere.

sleep() Function in Javascript

function sleep(milliseconds) { 
        var start = new Date().getTime(); 
        for (var i = 0; i < 1e7; i++) { 
                if ((new Date().getTime() - start) > milliseconds){ break; } 
        } 
}

Usage

//Sleep for 1 second (1000 milliseconds). 
console.log(new Date()); 
console.log('Dude!'); 
sleep(1000); 
console.log(new Date());


Tuesday, December 25, 2012

Multivalue Checkbox - jQuery plugin


Recently, I was looking for multivalue checkbox which gives user to select multiple options. I can do it with radio button but as there isn't required space to give 3 or 4 radio button and it's lable as well as some designing issue I was looking for multivalues checkbox.

Finally, I have made jQuery plugin which convert my html checkbox to multivalue checkbox with it's multiple options icon image. Here I have just hide html checkbox and add one img tag before checkbox which represented the selected option's icon.

You can review full source code on Github repository, and Click Here for DEMO.

Hope this help and don't forget to submit comment or issue.