Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery:FadeIn在图像src交换上_Javascript_Jquery_Html_Fadein - Fatal编程技术网

Javascript Jquery:FadeIn在图像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); 但这是行不通的 有人能建议一种方法来调整赛门铁克以

我有一段JQuery脚本,可以在单击时更改图像的src:

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");
    })​