的推拉類不能用於排序。 您可以通過多種方式實現您想要的效果:
- Javascript/jQuery。查看insertBefore和insertAfter方法。
- 使用flexbox。使用flexbox可以訪問屬性「訂單」。
我的選擇是Flexbox。 有關此檢查的更多信息https://css-tricks.com/snippets/css/a-guide-to-flexbox/
我爲您做了以下元素交換函數,如果您不想使用flexbox,應該將其用作jQuery函數。
(function ($) {
$.fn.swapElements = function (opties) {
//Variables
var settings = $.extend({
targetResolution: 768, //Trigger swapping of elements on this resolution
changeWith: '', //Which element should be swapped $('#object2')
changeSpeed: 30,
resize: true //Check for resize event
}, opties);
var a = this;
var b = settings.changeWith;
var tmp = $('<span>').hide();
var doSwap = function() {
var windowWidth = $(window).width();
var firstElement = $('#' + a.attr('id') + ', #' + settings.changeWith.attr('id')).first().eq(0).attr('id');
if (windowWidth <= settings.targetResolution && firstElement === a.attr('id')) {
a.before(tmp);
b.before(a);
tmp.replaceWith(b);
} else if (windowWidth > settings.targetResolution && firstElement === b.attr('id')) {
b.before(tmp);
a.before(b);
tmp.replaceWith(a);
}
}
$(document).ready(function() {
doSwap();
});
if (settings.resize) {
//Check on resize
$(window).resize(function() {
clearTimeout($.data(this, 'resizeTimer'));
$.data(this, 'resizeTimer', setTimeout(function() {
doSwap();
}, settings.changeSpeed));
});
}
return this;
};
}(jQuery));
這可以這樣使用:
$('#el1').swapElements({
changeWith: $('#el2'),
// changeSpeed: 30,
// targetResolution: 768,
// resize: true
});
可以使用Flexbox的改變順序。 – athi
我發現這個SO問題可能對您有所幫助(包括示例+ pro和con的包括):http://stackoverflow.com/a/31918297/5178016 –