jquery 闪耀效果,动画无需悬停作为触发器
我正在使用 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>
请帮助我,谢谢
问候
i am using this amazing Jquery shine time by Addy Osmani. It works perfectly fine since all i did was copied and pasted it :D
but then i need the shine effect to automatically animate periodically as soon as the image loads without having to be hovered first, how can i achieve this ? to be honest i have almost zero knowledge when it comes to jquery and or javascript
here's the code:
<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>
Please help me, thanks
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下,或者如果您想自定义它,请更改我放置所有
$('thumb_container'
) 的代码:)Try that, or if you want to customise it, change the code where i have put all of the
$('thumb_container'
) :)如果您有想要在
.hover
事件助手中触发的代码,则可以通过调用.hover()
函数来触发该事件,而无需传递任何参数。澄清一下:如果您想模拟 #largephoto 上的悬停事件,只需调用以下命令:
If you have the code you want to trigger in a
.hover
event helper, you can trigger that event by calling the.hover()
function without passing any parameters.To clarify: If you want to simulate the hover event on #largephoto, simply call this: