跳至主要内容
CSS-Tricks
  • 文章
  • 笔记
  • 链接
  • 指南
  • 年鉴
  • 随机排列
搜索

文章标签
shuffle

1 篇文章
{
,

}
随机排列子元素的文章直接链接
jQuery 随机数 随机化 随机排列

随机排列子元素

$.fn.shuffleChildren = function() {
    $.each(this.get(), function(index, el) {
        var $el = $(el);
        var $find = $el.children();

        $find.sort(function() {
            return 0.5 - Math.random();
        });

        $el.empty();
        $find.appendTo($el);
    });
};

使用

$(".parent-element").shuffleChildren();

查看代码笔
jQuery 随机排列函数
by Chris Coyier (@chriscoyier…

Avatar of Chris Coyier
Chris Coyier 于 2019 年 2 月 19 日

CSS-Tricks 由 DigitalOcean 提供支持。

关注 Web 开发的最新动态

订阅我们精心制作的时事通讯

DigitalOcean
  • 关于 DO
  • Cloudways
  • 法律信息
  • 获取免费积分!
CSS-Tricks
  • 为我们写作!
  • 与我们合作广告
  • 联系我们
社交
  • RSS 订阅
  • CodePen
  • Mastodon
  • X
返回顶部

© 2024 . All rights reserved.