jquery闪耀效果,动画而不悬停作为触发器

时间:2010-12-01 10:23:53

标签: jquery animation jquery-effects

我正在使用Addy Osmani这个惊人的Jquery shine time。它的工作完全正常,因为我所做的就是复制和粘贴它:D

然后我需要闪耀效果,一旦图像加载就会定期自动动画,而不必先徘徊,我怎样才能实现这一目标?说实话,我对jquery和javascript的知识几乎为零

这是代码:

<script type="text/javascript">
$(document).ready(function(){
    /*Your ShineTime Welcome Image*/
    var default_image = 'images/large/default.jpg';
    var default_caption = 'Welcome to ShineTime';

    /*Load The Default Image*/
    loadPhoto(default_image, default_caption);


    function loadPhoto($url, $caption){
        /*Image pre-loader*/
        showPreloader();
        var img = new Image();
        jQuery(img).load( function(){
            jQuery(img).hide();
            hidePreloader();
        }).attr({ "src": $url });

        $('#largephoto').css('background-image','url("' + $url + '")');
        $('#largephoto').data('caption', $caption);
    }

    /* When a thumbnail is clicked*/
    $('.thumb_container').click(function(){
        var handler = $(this).find('.large_image');
        var newsrc  = handler.attr('src');
        var newcaption  = handler.attr('rel');
        loadPhoto(newsrc, newcaption);
    });

    /*When the main photo is hovered over*/
    $('#largephoto').hover(function(){

        var currentCaption  = ($(this).data('caption'));
        var largeCaption = $(this).find('#largecaption');

        largeCaption.stop();
        largeCaption.css('opacity','0.9');
        largeCaption.find('.captionContent').html(currentCaption);
        largeCaption.fadeIn()



        largeCaption.find('.captionShine').stop();
        largeCaption.find('.captionShine').css("background-position","-550px 0"); 
        largeCaption.find('.captionShine').animate({backgroundPosition: '550px 0'},700);
    },
    function(){
        var largeCaption = $(this).find('#largecaption');
        largeCaption.find('.captionContent').html('');
        largeCaption.fadeOut();
    });

    /* When a thumbnail is hovered over*/
    $('.thumb_container').hover(function(){  
        $(this).find(".large_thumb").stop().animate({marginLeft:-7, marginTop:-7},200);
        $(this).find(".large_thumb_shine").stop();
        $(this).find(".large_thumb_shine").css("background-position","-99px 0"); 
        $(this).find(".large_thumb_shine").animate({backgroundPosition: '99px 0'},700);

    },
    function(){
        $(this).find(".large_thumb").stop().animate({marginLeft:0, marginTop:0},200);
    });

    function showPreloader(){
        $('#loader').css('background-image','url("images/interface/loader.gif")');
    }

    function hidePreloader(){
        $('#loader').css('background-image','url("")');
    }
});
</script>

请帮助我,谢谢

此致

2 个答案:

答案 0 :(得分:2)

 setInterval(function() {
      $('.thumb_container').find(".large_thumb").stop().animate({marginLeft:-7, marginTop:-7},200);
        $('.thumb_container').find(".large_thumb_shine").stop();
        $('.thumb_container').find(".large_thumb_shine").css("background-position","-99px 0"); 
        $('.thumb_container').find(".large_thumb_shine").animate({backgroundPosition: '99px 0'},700);
   }, 3000);

尝试一下,或者如果你想自定义它,请更改我放置所有$('thumb_container')的代码:))

答案 1 :(得分:1)

如果您要在.hover事件助手中触发代码,则可以通过调用.hover()函数来触发该事件,而不传递任何参数。

澄清一下:如果您想在#largephoto上模拟悬停事件,只需调用:

$("#largephoto").hover();