开发者

JQuery simple slider issue on timeOut

I have a function called slideMe() and I need to launch that with delay of some seconds for each slider links.

jquery version is 1.4.2

code is:

$(document).ready(function(){
    var img_id;
    var clicked;

 function slideMe(img_id){

       $('.slider-menu-item').css('color','#fff');
       $('#'+img_id).css('color','#EBE1B9')开发者_开发技巧;
       $('.slider-img').hide();
       $('#slider-img-'+img_id).fadeIn(600);

    };

$.each($('.slider-menu-item'),function(){

   img_id = $(this).attr("id");
   setTimeout("slideMe()",900);

    console.log(img_id)

});
   $('.slider-menu-item').live('click',function(){
       img_id = $(this).attr("id");
       clicked = 1;
    slideMe(img_id);
}); 

});//end document.ready

but in console logs I receive error that says:

slideMe is not defined

How I can do?


You need to define the slideMe function outside of the document.ready handler. Also it would be better to pass directly the method to setTimeout instead of using strings. Also the slideMe method expects an argument so make sure you pass it:

function slideMe(img_id) {
    $('.slider-menu-item').css('color', '#fff');
    $('#' + img_id).css('color', '#EBE1B9');
    $('.slider-img').hide();
    $('#slider-img-' + img_id).fadeIn(600);
}

$(document).ready(function() {
    var img_id;
    var clicked;

    $('.slider-menu-item').each(function() {
        img_id = $(this).attr('id');
        setTimeout(function() {
            slideMe(img_id);    
        }, 900);
    });

    $('.slider-menu-item').live('click',function() {
        img_id = $(this).attr("id");
        clicked = 1;
        slideMe(img_id);
    }); 
});


try slideMe=function(){...} instead of function slideMe(){...}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜