- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个相当简单的网格游戏,用户必须单击图 block 才能显示下面的内容。我遇到的第一个问题是实现一个点击功能,该功能不仅会删除点击的图 block ,还会删除其周围的一些图 block ,最好是随机的。
我当前的代码:
$('.layer img').click(function() {
$(this).css ('display', 'none');
});
非常感谢任何扩展我的简单代码的帮助。
最佳答案
您可以计算 sibling 的数量并随机隐藏其中的一些,如下所示:
$('.layer img').click(function() {
sib = $(this).siblings();
rand = Math.floor((Math.random()*sib.length)+1);
for (i=0;i<rand;i++) {
sib.eq(i).css ('display', 'none');
}
$(this).css ('display', 'none');
});
正如OP所评论的,我在这里添加增强版本,以随机选择上一个或下一个 sibling ,总共最多5个:
$('.layer img').click(function() {
sib = $(this).siblings();
rand = Math.floor((Math.random()*sib.length)+1);
rand = Math.min(5,rand);
aprev = $(this);
anext = $(this);
for (i=0;i<rand;i++) {
if (Math.floor((Math.random()*2)+1) == 1 ) { //random go prev or next
if (aprev.prev().length) {
aprev = aprev.prev();
aprev.css ('display', 'none');
} else {
anext = anext.next();
anext.css ('display', 'none');
}
} else {
if (anext.next().length) {
anext = anext.next();
anext.css ('display', 'none');
} else {
aprev = aprev.prev();
aprev.css ('display', 'none');
}
}
}
$(this).css ('display', 'none');
});
代码增长了一点,因为我们必须控制是否不再有上一个或下一个 sibling ,并且在这种情况下恢复到另一个。
关于javascript - 如何为平铺网格中的元素实现单击功能,当单击它时,它及其附近的元素会淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12784713/
我正在尝试制作一种能够解决拼贴问题中的大图 block 集的算法。现在它能够根据宽度和高度找到正确的 Tiles 来放置,但是在使其正确递归方面存在一些问题。 如您所见,这个想法是,在放置的每个图 b
有什么方法可以轻松地平铺 mdi parent 的所有表单 child 吗?我正在寻找 windows 提供的大部分功能,瓷砖级联。有谁知道一个简单的方法? 最佳答案 试试这些... // Tile
我有一个大 jpg,其分辨率为 x * 256/x * 256。我想将此图像切割为 256x256 的图块,命名约定为 {zoom}-{x}-{y}.jpg。过去我使用 ZoomifyExpress
如何使用ImageMagick平铺图像?我认为我不能使用montage,因为我希望将列偏移原始图像高度的50%。 展示我正在尝试做的事可能更容易: 从...开始: 结尾为: 谢谢! 最佳答案 感谢Fr
是否可以在 XNA 中平铺图像以使其填满整个矩形?我试过用谷歌搜索这个主题,但我找不到任何似乎有用的东西(虽然我可能遗漏了一些明显的东西)。我找到了 this MSDN page ,但我似乎无法让它工
我无法找到答案,为什么我为图 block map 制作的图 block 表在使用 libGDX 在屏幕上移动时会创建垂直白线和不稳定的水平线。 这是显示白色垂直线的视频:https://www.you
有谁知道 GitHub Java version of Tiled 中如何临时支持视差图层吗?工作正常吗? 它可以编译,并且执行得很好。但是,如果我将图层设置为viewplane distance 0
在我制作的平台游戏中,我需要加载图 block 才能创建关卡,但在下面的代码中我似乎遇到了问题。它说我在这部分有一个错误: String[] skips = skip.split(" "); 但对我来
使用 pdfimages 提取图像和 mupdf/mutool到目前为止工作正常。 使用 FreePDF 生成的 PDF 中的图像总是被切片,因此一个图像会生成多个图像文件。 有什么技巧可以避免这种情
我正在尝试使用 Tiled 编写基于 rts-like-tile 的游戏和 slick2d。 我不知道如何处理多图 block 对象,例如建筑物,如何创建、保存等等。移动它们。 最佳答案 一种解决方案
我想用一张图片来编写一个平铺 map 。它应该是一个 5x5 的小图片区域。我写了一些带有 2 个嵌套循环的 Javascript 代码。使用此解决方案,仅打印 1 张图片。当我在第二个循环中删除 b
我正在尝试使用 Slick2D 和 Tiled Map Editor 制作一个基本的 2D 游戏。我已经弄清楚如何使用 TileProperties 进行基本的碰撞检测,但我不确定对象如何与 map
我正在尝试创建一个无限滚动的分页 UIScrollView 我一直在关注 Advanced UIScrollView Techniques来自 WWDC 2010 的视频,但是我不确定如何为分页 UI
好吧,假设我有一个像本网站一样的冷却平铺背景。 http://www.leeslights.com/colors-shapes-sizes-and-prices.html 我将如何使图像平铺到浏览器,
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
这个问题在这里已经有了答案: CSS-only masonry layout (5 个答案) 关闭 2 年前。
我是一名优秀的程序员,十分优秀!