1新建html文档。2准备好需要用到扑克牌每一张都是图片。3书写hmtl代码。<main> <ul class="imgbox"> <li class="pai"></li> </ul> <div class="btnleft"><</div> <div class="btnright">></div></main>4书写css代码。<style>* { margin: 0; padding: 0; l**t-style: none; }html, body { width: 100%; height: 100%; overflow: hidden; }body { background-image: url(images/deck.png); background-size: cover; background-repeat: no-repeat; }main { width: 1000px; height: 100%; margin: 0 auto; }.imgbox { width: 100%; height: 500px; position: relative; }.pai { width: 90px; height: 140px; position: absolute; left: calc(50% - 45px); top: 0; background-size: 100% 100%; opacity: 0; border: 2px solid transparent; }.btnleft, .btnright { width: 120px; height: 50px; position: absolute; left: 0; right: 0; margin: 20px auto; background: palegreen; color: #fff; text-align: center; font-size: 30px; line-height: 50px; border-radius: 5px; cursor: pointer; }.active { border: 2px solid red; }.btnleft { top: 450px; }.btnright { top: 510px; }</style>5书写并添加js代码。<script>var arr=['c','d','h','s'];var newarr=[];var obj={};var newobj={'1':'a','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8','9':'9','10':'t','11':'j','12':'q','13':'k'};while(newarr.length<52){var num=math.ceil(math.random()*13);var color=arr[math.floor(math.random()*arr.length)];if(!obj[`${num}_${color}`]){ //obj[] 表示对象[属性名]obj[`${num}_${color}`]=true;newarr.push({num,color}); //json格式时,变量的名称作为属性名,变量的值作为属性值}}var n=0;for(var i=0;i<7;i++){for(var j=0;j<=i;j++){$('<li>').addclass('pai').data('num',newarr[n].num).prop('id',`${i}_${j}`).css('backgroundimage',`url(images/${newobj[newarr[n].num]}${newarr[n].color}.png)`).delay(n*40).animate({top:i*50,left:455-i*50+100*j,opacity:1},300).appendto('ul.imgbox');n++;}}for(var i=n;i<newarr.length;i++){$('<li>').addclass('pai zuo').data('num',newarr[i].num).css('backgroundimage',`url(images/${newobj[newarr[i].num]}${newarr[i].color}.png)`).delay(i*40).animate({top:460,left:255,opacity:1},300).appendto('ul.imgbox');}var m=**;$(document).on('click','li',function(){var id=$(th**).prop('id');var next1=$(`#${parseint(id.split("_")[0])+1}_${id.split("_")[1]}`);var next2=$(`#${parseint(id.split("_")[0])+1}_${parseint(id.split("_")[1])+1}`);if(next1[0]||next2[0]){return;}$(th**).toggleclass('active');if($(th**).hasclass('active')){$(th**).animate({top:'-=20'},300);}else{$(th**).animate({top:'+=20'},300);}if(!m){m=$(th**);if($(th**).data('num')==13){$('.active').animate({top:0,left:1000,opacity:0},300,function(){$('.active').remove();})m=**;}}else{if($(th**).data('num')+m.data('num')==13){$('.active').animate({top:0,left:1000,opacity:0},300,function(){$('.active').remove();})}else{$('.active').removeclass('active').animate({top:'+=20'});}m=**;}})var index=0;$('.btnright').click(function(){$('.zuo').eq(-1).animate({left:'+=400',zindex:index++},300).removeclass('zuo').addclass('you');})$('.btnleft').click(function(){$('.you').each(function(index,val){$(val).delay(index*40).animate({left:'-=400',zindex:index},300).removeclass('you').addclass('zuo');})})</script>6代码整体结构。6本页面未经许可获取自百度经验7查看效果。end 20210311