SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to call a function in jquery?

    I have:
    Code:
    (function( $ ){
    
        $.fn.fade = function(options) {
            var settings = {
                'speed': 5000            
            }
            if ( options ) {
                $.extend( settings, options );
            }
            
            var tickerIndex = 0;
            var tickerRef = this;
            function fadeOut() {
                var ticker = tickerRef.children().eq(tickerIndex);
                ticker.css("display", "block");
                //document.getElementById("ticker0").childNodes[tickerIndex].style.removeAttribute("filter");
                ticker.css('filter','none');
                //var node = document.getElementById(settings.id).childNodes[i];
                //node.style.removeAttribute("filter");
    
                ticker.fadeOut(settings.speed, function () {
                    //$(this).css('filter','');
                    
                    //var node = document.getElementById(this).childNodes[i];
                    //node.style.removeAttribute("filter");
                    //document.getElementById("ticker0").style.removeAttribute("filter");
                    ticker.css("display", "none");
                    tickerIndex++;
                    
                    if (tickerIndex == tickerRef.children().length) {
                        tickerIndex = 0;
                    }				
                    fadeOut();
                });
            };		
    		fadeOut();		        
        };
    	
    })( jQuery );
    I want to change fadeOut() to setTimeout('fadeOut()', 10000) but it says fadeOut() is undefined. How should I call it?

    Thanks!

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    jQuery has a method you can use called delay(), basically you use it like any other method but it does the same thing as calling a setTimeout() function manually.

    http://api.jquery.com/delay/
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Is this how it is done?

    fadeOut().delay(10000);

    Thanks.

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't work. Please help. Thanks

  5. #5
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The delay method needs to be declared before the fadeOut method, see the below example.

    Code JavaScript:
    $('div').delay(10000).fadeOut();
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry Chris, I think you got me wrong.

    I want the fadeOut() at lines 3 and 6 from the bottom of the code to call fadeOut() at a delay of 10000milisecs. Not a $('div').

    How should I call it? Thanks.

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,904
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    Code javascript:
    setTimeout(function() { fadeOut(); }, 10000);

    or

    Code javascript:
    setTimeout(fadeOut, 10000);

    (both do the same thing, but I personally prefer the syntax of the former)

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry...it says fadeOut() is undefined.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •