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?

  • And you see the implementation of these functions in jQuery itself. True, there seems to be not very convenient to dig into it. - Oleg Arkhipov
  • 2
    There are two types of jQuery file - one compact (for those who don't care what's inside) and readable (for those who care about what's inside) - AseN
  • @Asen, I know, but in the second one it’s also not very convenient. Although the implementation of the function, I think, is easy to find. - Oleg Arkhipov
  • I incorrectly called the function. It was necessary to fadeOut (). fadeIn is a smooth appearance. - Ghringo
  • one
    @Construct, in jQury, the jQury function fadeOut written via the non-size-sized animate function - Specter

0