Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing callback function #2

Open
w3b-beweb opened this issue Feb 20, 2011 · 0 comments
Open

missing callback function #2

w3b-beweb opened this issue Feb 20, 2011 · 0 comments

Comments

@w3b-beweb
Copy link

FOA, thanks for your great plugin. I think it should be usefull to add the ability to pass at least one parameter (speed?) and to call a callback function. So I've modified one of your text effects like this:

$.fn.typewriter = function(speed, callback) {
this.each(function() {
var $ele = $(this), str = $ele.text(), progress = 0;
$ele.text('');
var timer = setInterval(function() {
$ele.text(str.substring(0, progress++) + (progress & 1 ? '_' : ''));
if (progress >= str.length){
clearInterval(timer);
if (typeof callback == 'function') { // make sure it is a function
callback.call(this); // brings the scope to the callback
}
}
}, speed);
});
return this;
};

Bye, Daniele.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant