洗牌不工作

shuffleJs not working

我在使用它时遇到了问题。我是 javascript 的新手并且 我正在使用 https://github.com/Vestride/Shuffle 为了获得额外的帮助,我阅读了本教程 https://www.youtube.com/watch?v=t9Wct6cGugA

我觉得我输入的一切都是正确的(即使它是德文的)但它不能正常工作。请原谅我,因为我还在学习如何通过阅读来区分 jQuery 和 JavaScript。我的按钮没有像教程中那样给我想要的结果。非常感谢任何帮助!

$(function () {
    gridContainer = $('#shuffleContainer');
    var sizer = gridContainer.find('.col-md-4');

    gridContainer.shuffle ({
        sizer: sizer,
        speed: 500,
        easing: 'ease-out'
    });

    $('#btnAll').on('click', function () {
        gridContainer.shuffle('shuffle', function($el, shuffle) {
            return true;
        });
    });

    $('#btnFurniture').on('click', function () {
        gridContainer.shuffle('shuffle', function($el, shuffle) {
            return $el.data('group') == 'Furniture';
        });
    });

    $('#btnPet').on('click', function () {
        gridContainer.shuffle('shuffle', function($el, shuffle) {
            return $el.data('group') == 'Pet';
        });
    });

    $('#btnElectronic').on('click', function () {
        gridContainer.shuffle('shuffle', function($el, shuffle) {
            return $el.data('group') == 'Electronic';
        });
    });

    $('#btnTransportation').on('click', function () {
        gridContainer.shuffle('shuffle', function($el, shuffle) {
            return $el.data('group') == 'Transportation';
        });
    });
});
h1 {
    margin-bottom: 20px;
}
.container {
    padding-top: 50px;
}
.selector {
    margin-top: 20px;
}
#shuffleContainer {
    margin-top: 10px;
}

.col-md-4 {
    margin-bottom: 150px;
    height: 270px;
}
<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0 initial-scale=1" />
    <title>My Shuffle Demo</title>

    <link href="Content/bootstrap.css" rel="stylesheet" />
    <link href="css/style.css" rel="stylesheet" />

    <script src="Scripts/jquery-1.11.0.js"></script>
    <script src="Scripts/bootstrap.js"></script>
    <script src="shuffle/shuffle.js"></script>
    <script src="js/script.js"></script>
    <script src="Scripts/jquery.shuffle.js"></script>
    <script src="Scripts/jquery.shuffle.modernizr.js"></script>


</head>

<body>

    <div class="container">
        <h1>Shuffle.js Demo</h1>
        <div class="row">
            <div class="col-md-12">
                Shuffle.js is the best <a href="http://vestride.github.io/Shuffle/">Shuffle It Up!</a>
            </div>
        </div>
        <div class="row selector">
            <div class="col-md-12">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" id="btnAll">All</button>
                    <button type="button" class="btn btn-default" id="btnFurniture">Furniture</button>
                    <button type="button" class="btn btn-default" id="btnPet">Pet</button>
                    <button type="button" class="btn btn-default" id="btnElectronic">Electronic</button>
                    <button type="button" class="btn btn-default" id="btnTransportation">Transportation</button>
                </div>
            </div>
        </div>
        <div id="shuffleContainer" class="row">
            <div class="col-md-4" data-group="furniture">
                <img src="image/blackChair.jpg" class="img-responsive"/>
             </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/blackBed.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="pet">
                <img src="image/blackKitten.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="transportation">
                <img src="image/blueBike.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/blueChair.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="transportation">
                <img src="image/chromeBike.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="pet">
                <img src="image/grayCat.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="electronic">
                <img src="image/iphone.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="pet">
                <img src="image/jindoDog.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="electronic">
                <img src="image/lenovoLap.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="electronic">
                <img src="image/macBook.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="pet">
                <img src="image/monkey.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/orangeBed.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="pet">
                <img src="image/penisCat.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/pinkBed.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="pet">
                <img src="image/pugDog.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/PurpleChair.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/redChair.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="electronic">
                <img src="image/samsungEdge.jpg" class="img-responsive" />
            </div>
            <div class="col-md-4" data-group="furniture">
                <img src="image/yellowChair.jpg" class="img-responsive" />
            </div>
        </div>
    </div>


</body>
</html>

我能够在 fiddle 中重现您的问题并找到了原因。 在单击事件中,您遇到区分大小写的问题 Transportation。它应该匹配 data-group="transportation"

中区分大小写的值

解决方法是调整点击事件中的大小写:

$('#btnTransportation').on('click', function () {
    gridContainer.shuffle('shuffle', function($el, shuffle) {
        return $el.data('group') == 'transportation';
    });
}); 

检查working demo

希望对您有所帮助!