Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 单击事件的fadeIn效果_Javascript_Jquery - Fatal编程技术网

Javascript 单击事件的fadeIn效果

Javascript 单击事件的fadeIn效果,javascript,jquery,Javascript,Jquery,我无法使用fadeIn效果处理图像的单击事件 我希望它们在单击时淡入淡出和淡出切换起作用,但fadeIn不起作用。我搜索并尝试了所有发现的东西,但都没有成功 我确信这是一件非常简单的事情,我忽略了它,但我无法理解 提前感谢您的帮助 $(document).ready(function() { // preload images $("#image_list a").each(function() { var swappedImage = new Image();

我无法使用
fadeIn
效果处理图像的单击事件

我希望它们在单击时淡入<代码>淡出和
淡出切换
起作用,但
fadeIn
不起作用。我搜索并尝试了所有发现的东西,但都没有成功

我确信这是一件非常简单的事情,我忽略了它,但我无法理解

提前感谢您的帮助

$(document).ready(function() {
    // preload images
    $("#image_list a").each(function() {
        var swappedImage = new Image();
        swappedImage.src = $(this).attr("href");
    });
    // set up event handlers for links    
    $("#image_list a").click(function(evt) {
        var imageURL = $(this).attr("href");
        $("#image").attr("src", imageURL).fadeIn(1000);

        var caption = $(this).attr("title");
        $("#caption").text(caption);

        // cancel the default action of the link
        evt.preventDefault();
    }); // end click
    // move focus to first thumbnail
    $("li:first-child a").focus();
}); // end ready

您必须首先将这些预加载的图像放入目标元素并隐藏它。然后你就可以法登了

$(document).ready(function() {
  // preload images
  $("#image_list a").each(function() {
    var swappedImage = new Image();
    swappedImage.src = $(this).attr("href");
    $(this).append(swappedImage);
    $(swappedImage).hide();
  });
  // set up event handlers for links    
  $("#image_list a").click(function(evt) {

    // cancel the default action of the link
    evt.preventDefault();
    $("img").fadeIn(5000);

    var caption = $(this).attr("title");
    $("#caption").text(caption);
  }); // end click
  // move focus to first thumbnail
  $("li:first-child a").focus();
}); // end ready

您试图在何处使用
fadeIn
?我在代码$('#image').attr(“src”,imageURL).fadeIn(1000)中没有看到它;对不起,我以前从未在这里发布过…在设置源代码后,您试图在图片中淡出,对吗?我相信是这样的。。。我修改了代码来显示我在哪里做fadeIn。你也能显示你的html吗?这把整个页面弄得一团糟。啊!我希望我能把HTML放到上面让你看。非常感谢。这样做的想法是,您应该担心这两行:
$(this).append(swappedImage)$(swappeImage.hide()