Skip to content

Instantly share code, notes, and snippets.

@madrobby
Created April 21, 2011 08:47
Show Gist options
  • Save madrobby/934008 to your computer and use it in GitHub Desktop.
Save madrobby/934008 to your computer and use it in GitHub Desktop.
// tweet-sized, and does (approximately) the same thing
var t=document.all,l=t.length,w='-webkit-trans';while(l--)t[l].style.cssText+=w+'ition:all,20s;'+w+'form:rotate('+Math.random()+'rad)'
@jedisct1
Copy link

One less char:
i=0,d=document.all,w='-webkit-trans';while(e=d[i++])e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@madrobby
Copy link
Author

How about:

i=-1,w='-webkit-trans';while(e=document.all[++i])e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@119 characters

@jedisct1
Copy link

i=0,w='-webkit-trans';while(e=document.all[i++])e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@2ag
Copy link

2ag commented Apr 21, 2011

for(i=0,s='-webkit-trans';;)document.getElementsByTagName('div')[i++].style.cssText+=s+'ition:20s;'+s+'form:rotate('+Math.random()+'rad)'

Only on div as the original. 137char !!! tweeted !!!! :-)

But I use error recovery from webkit... this will not work in other browsers... :-(

@marcheiligers
Copy link

Does only divs as the original but has errors on length and item properties:
w='-webkit-trans';a=document.querySelectorAll("div");for(e in a)a[e].style.cssText+=w+'ition:all,20s;'+w+'form:rotate('+Math.random()+'rad)'

@jedisct1
Copy link

116 chars:

for(i=0,w='-webkit-trans';e=document.all[i++];)e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@marcheiligers
Copy link

Ooh, using 2ag's for loop but with querySelectorAll gives 134 chars and only divs (but still the error)

for(i=0,s='-webkit-trans';;)document.querySelectorAll("div")[i++].style.cssText+=s+'ition:20s;'+s+'form:rotate('+Math.random()+'rad)'

@sebastien-p
Copy link

for(i=0,w='-webkit-trans';e=document.all[i++];)e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

Edit : oops, same idea as @jedisct1 :)

@joside
Copy link

joside commented Apr 21, 2011

s='-webkit-trans';document.styleSheets[1].addRule('div',s+'ition:20s;'+s+'form:rotate('+Math.random()+'rad)')
Just an experiment with 109 chars, no errors for me but every div will rotate by the same value

@2ag
Copy link

2ag commented Apr 21, 2011

Using thomas's last proposal + querySelectorAll from marcheilligers and we have 139 characters ! and no errors :-)

i=-1,w='-webkit-trans';while(e=document.querySelectorAll('div')[++i])e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@marcheiligers
Copy link

137 chars, only divs, no errors, based on @jedisct1 loop with querySelectorAll
If I could save one more char somewhere the var could go back in :-(

for(i=0,w='-webkit-trans';e=document.querySelectorAll("div")[i++];)e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@2ag
Copy link

2ag commented Apr 21, 2011

And starting i to 0 and i++ in place of ++i : 137 characters. Still no errors.

i=0,w='-webkit-trans';while(e=document.querySelectorAll('div')[i++])e.style.cssText+=w+'ition:20s;'+w+'form:rotate('+Math.random()+'rad)'

@stdclass
Copy link

w="-webkit-trans";i=0;while(e=document.querySelectorAll("div")[i++])e.style.cssText+=w+"ition:20s;"+w+"form:rotate("+i/10+"rad)"

@dave1010
Copy link

109: like @joside's but with * instead of div

s='-webkit-trans';document.styleSheets[1].addRule('*',s+'ition:20s;'+s+'form:rotate('+Math.random()+'rad)')

Edit:

Not sure where the 20s came from but 9s looks just as good:

s='-webkit-trans';document.styleSheets[1].addRule('*',s+'ition:9s;'+s+'form:rotate('+Math.random()+'rad)')

@marcheiligers
Copy link

I think @joside has won this game.

@sebastien-p
Copy link

@marcheiligers : what if there is actually not any document.styleSheets ?

@dave1010
Copy link

Should be able to get it to work in Opera with '-o-trans', which would shave 5 chars but I can't get it to work :-(. Means you loose 1% of browser market share though.

@jdalton
Copy link

jdalton commented Apr 21, 2011

[].map.call(document.all,function(e,s){s='-webkit-trans';e.style.cssText+=s+'ition:20s;'+s+'form:rotate('+Math.random()+'rad)'})

@vladocar
Copy link

Array.prototype.slice.call(document.all).forEach(function(e,s){s='-webkit-trans';e.style.cssText+=s+'ition:20s;'+s+'form:rotate('+Math.random()+'rad)'})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment