Skip to content

Instantly share code, notes, and snippets.

@SauloSilva
Created August 1, 2013 19:14
Show Gist options
  • Save SauloSilva/6134306 to your computer and use it in GitHub Desktop.
Save SauloSilva/6134306 to your computer and use it in GitHub Desktop.
Resize, element html, pure javascript.
var object = undefined
, minimum = undefined
, count = 0
, limit = 0
, skip = 5
, interval = undefined;
function expand(width) {
object = document.getElementById('super');
minimum = object.offsetWidth;
limit = width;
stop();
interval = setInterval('toggle()', 0.1);
if (count == 0 ) { count += minimum };
}
function toggle() {
if (limit > minimum){
increment()
} else{
decrement()
}
document.getElementById('super_expand').style.width = count + "px";
object.style.width = count + "px";
}
function increment(){
if (limit > count){
count += skip;
} else{
stop();
}
}
function decrement(){
if (limit < count){
count -= skip;
} else{
stop();
}
}
function stop() {
clearInterval(interval);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment