无法淡入使用 jquery 加载的图像

问题描述 投票:0回答:1

我是 jQuery 的新手,我不明白为什么图像会显示,但它不会像 jQuery 文档所建议的那样淡入。

<!DOCTYPE HTML>
<html lang='en'>
<head>
<meta charset="UTF-8">
<title>slide show test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<img id="image" alt="slide" style="opacity:0.5;"/>
<script>
var x="tiananmen-square-600.webp";
$("#image").attr('src', x, function() {
        $("#image").fadeIn( "slow");
        });
</script>
</body>
</html>

请帮忙。

jquery image fadein
1个回答
0
投票

.attr() 不接受第三个参数。

我想你想要这样的东西

$('#image').hide().attr('src', x).fadeIn('slow');

那就是

  1. 选择
    #image
    元素
  2. 最初隐藏它
  3. 设置它的
    src
    属性
  4. 淡入
© www.soinside.com 2019 - 2024. All rights reserved.