Javascript Jquery:FadeIn在图像src交换上
我有一段JQuery脚本,可以在单击时更改图像的src:Javascript Jquery:FadeIn在图像src交换上,javascript,jquery,html,fadein,Javascript,Jquery,Html,Fadein,我有一段JQuery脚本,可以在单击时更改图像的src: var imgsrc; $('#thumbs img').click(function(){ imgsrc = $(this).attr('src'); $('#mainphoto img').attr('src', imgsrc); 我想知道是否有办法添加.fadeIn() 我试过: $('#mainphoto img').fadeIn().attr('src', imgsrc); 但这是行不通的 有人能建议一种方法来调整赛门铁克以
var imgsrc;
$('#thumbs img').click(function(){
imgsrc = $(this).attr('src');
$('#mainphoto img').attr('src', imgsrc);
我想知道是否有办法添加.fadeIn()
我试过:
$('#mainphoto img').fadeIn().attr('src', imgsrc);
但这是行不通的
有人能建议一种方法来调整赛门铁克以适应这种情况吗?试试看
$('#thumbs img').click(function(){
var imgsrc = $(this).attr('src');
$('#mainphoto img').fadeOut(function(){
$(this).attr('src', imgsrc).fadeIn();
});
});
试试这个
$('#thumbs img').click(function() {
var imgsrc = $(this).attr('src');
$('#mainphoto img').fadeOut().attr('src', imgsrc).load(function() {
$(this).fadeIn();
});
});
我为你做了一个例子
基本上,我所做的就是在图像上收听点击事件。执行单击时,我将当前图像的显示更改为无,也将图像的src更改为新的,然后执行fadeIn(恢复显示)
Javascript代码是:
$('#image').click(function(){
$(this).css("display", "none");
$('#image').attr('src', 'http://www.stat4you.com/theme/0.1.11/images/stat4you.png');
$("#image").fadeIn("slow");
})
在fadeIn()的jQuery文档页面中,还有一些类似的示例:
。attr()
已被弃用。使用.prop()。“它仍然有效。”弗拉迪斯拉夫库林,当然有效。这不是答案。只是一个评论/建议OK,只是为了澄清事实,@Musa是正确的.attr()
未被弃用。检查以确定。我站着纠正哇!快来这里的人!当我开始回答没有答案的问题时。。。顺便说一句,所有这些都是很好的答案。
$('#image').click(function(){
$(this).css("display", "none");
$('#image').attr('src', 'http://www.stat4you.com/theme/0.1.11/images/stat4you.png');
$("#image").fadeIn("slow");
})