Skip to content

Instantly share code, notes, and snippets.

@AMSTKO
Created September 19, 2011 13:40
Show Gist options
  • Save AMSTKO/1226521 to your computer and use it in GitHub Desktop.
Save AMSTKO/1226521 to your computer and use it in GitHub Desktop.
cedit.js
/**
* cedit - mr.ping
*
* cedit(e,'opacity',2000,0.1,'$');
* cedit(e,'width',100,10);
* cedit(e,'height',200,20,'$%');
* cedit(e,'top',300,30);
* cedit(e,'right',400,70,'$%');
*
* cedit(e,'height',600,600,null,function() {
* console.log('end')
* });
*
* cedit(e,'opacity',1000,0,'$',null,function(p,r) {
* console.log(r*100 + '%')
* });
*
* cedit(e,'background-position',200000,10000,'$px $px');
*
*/
function cedit(e,a,m,p,t,c,f){
var s=e.style,r=parseFloat(s[a]),g=10*(p-r)/(m<100?100:m),t=t?t:'$px';e['r'+a]=1;
(function u(){
r+=g;
s[a]= t.replace(/\$/gi,r);
f&&f.call(e,p,r);
p!=r.toFixed(2)&&e['r'+a]==1 ? setTimeout(u,10):function(){
e['r'+a]=0;
c&&c.call(e)
}()
})()
}
// mini
function cedit(e,a,m,p,t,c,f){var s=e.style,r=parseFloat(s[a]),g=10*(p-r)/(m<100?100:m),t=t?t:'$px';e['r'+a]=1;(function u(){r+=g;s[a]=t.replace(/\$/gi,r);f&&f.call(e,p,r);p!=r.toFixed(2)&&e['r'+a]==1?setTimeout(u,10):function(){e['r'+a]=0;c&&c.call(e)}()})()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment