gpt4 book ai didi

jquery - 如何从 16 张图片循环中隐藏 1 张图片

转载 作者:行者123 更新时间:2023-12-01 00:55:39 25 4
gpt4 key购买 nike

第一次在这里发帖,如果帖子不整洁,抱歉:)

我正在尝试用 jQuery 制作一个 15 张幻灯片的拼图,我的问题是这样的;我正在循环 16 个图像,我想隐藏最后一个图像并在拼图后显示它,但它不起作用,我尝试使用 fadeOut()hide()但它不起作用。

$(document).ready(function() {


for (var i = 0; i < 16; i++) {
var img = "<img src='img/" + i + ".png' id="+ i +">";
$("#board").append(img);
}

$("img#15").ready(function(){
$(this).hide();
});

$("img").each(function() {
var i = parseInt($(this).attr("id"));
var yAs = Math.floor(i / 4);
var xAs = i % 4;
$(this).data("yAs", yAs);
$(this).data("xAs", xAs);
var xPosition = xAs * 160;
var yPosition = yAs * 128;
$(this).css({"left": xPosition});
$(this).css({"top": yPosition});
});
});
img {
box-shadow: 5px 5px 3px #888888;
line-height: 0;
position: absolute;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Slidepuzzle jQuery!</title>
<link rel="stylesheet" href="slidepuzzle.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="slidepuzzle.js"></script>
</head>
<body>
<div id="board">

</div>
</body>
</html>

最佳答案

尝试在附加图像后使用 .find() 函数,如下所示: $("#board").find("img#15").hide();发生这种情况是因为您动态附加图像。

关于jquery - 如何从 16 张图片循环中隐藏 1 张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43407725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com