Jquery 按←、→键控制三个div互换位置?
发布网友
发布时间:2022-04-22 22:26
我来回答
共1个回答
热心网友
时间:2022-04-22 23:55
<div class="cont">
<div style="width: 100px; height: 100px; border: 1px solid red;float: left;">div1</div>
<div style="width: 100px; height: 100px; border: 1px solid red;float: left;">div2</div>
<div style="width: 100px; height: 100px; border: 1px solid red;float: left;">div3</div>
</div>
<script src="引入jquery"></script>
<script>
$(document).keydown(function (e) {
switch(e.which) {
case 37:
var $cont = $('.cont');
$cont.append($cont.find('div:first'));
break;
case 39:
var $cont = $('.cont');
$cont.prepend($cont.find('div:last'));
break;
}
});
</script>