I asked myself a question to write a function similar to the one in jQuery. But something is not very successful. What is wrong with this code?
window.onload = function () { function fadeIn() { var element = arguments[0]; var delay = arguments[1]; function alterElement() { var elementHeight = window.getComputedStyle(element, null).height; elementHeight = parseInt(elementHeight); elementHeight -= 10; element.style.height = elementHeight + 'px'; } for (var i = 0; i < 5; i++) setInterval(alterElement, delay); } var block = document.getElementById('block'); fadeIn(block, 500); }
Here is a piece of code from the jQuery source with the only mention of the word fadeOut:
// Generate shortcuts for custom animations jQuery.each({ slideDown: genFx( "show", 1 ), slideUp: genFx( "hide", 1 ), slideToggle: genFx( "toggle", 1 ), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" }, fadeToggle: { opacity: "toggle" } }, function( name, props ) { jQuery.fn[ name ] = function( speed, easing, callback ) { return this.animate( props, speed, easing, callback ); }; });
Personally, this piece does not tell me anything, but what about you?
jQury
functionfadeOut
written via the non-size-sizedanimate
function - Specter