我在解决这个问题时遇到了问题。我是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>
&#13;
答案 0 :(得分:1)
我能够在小提琴中重现你的问题,并发现了原因。
在点击事件中,您遇到区分大小写Transportation
的问题。它应与data-group="transportation"
修复方法是在点击事件中调整案例:
$('#btnTransportation').on('click', function () {
gridContainer.shuffle('shuffle', function($el, shuffle) {
return $el.data('group') == 'transportation';
});
});
检查working demo。
希望它有所帮助!