diff between padding and margin

http://blog.webassist.com/2010/01/the-difference-between-css-margins-and-padding/

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的 Vue2 实现找不同游戏的示例代码: HTML 文件: ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>找不同游戏</title> </head> <body> <div id="app"> <div class="image-container"> <img :src="originalImage" class="image" @click="showDiff = true"> <img :src="modifiedImage" class="image" v-if="showDiff"> <div class="diff" v-if="showDiff" v-for="(point, index) in diffPoints" :key="index" :style="{left: point.x + 'px', top: point.y + 'px'}"></div> </div> <div class="toolbar"> <button @click="checkDiff">检查差异</button> <span>{{score}} 分</span> <span v-if="showDiff">已用时 {{time}} 秒</span> </div> <div class="modal" v-if="gameOver"> <div class="modal-content"> <p>游戏结束,你的得分是 {{score}} 分!</p> <button @click="restartGame">重新开始</button> </div> </div> </div> </body> </html> ``` CSS 文件: ```css body { margin: 0; padding: 0; } .image-container { position: relative; } .image { max-width: 100%; height: auto; } .diff { position: absolute; width: 10px; height: 10px; background-color: red; } .toolbar { display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f5f5f5; } .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; } .modal-content { background-color: #fff; padding: 20px; border-radius: 5px; text-align: center; } .modal button { margin-top: 10px; padding: 5px 10px; background-color: #f5f5f5; border: none; border-radius: 5px; cursor: pointer; } .modal button:hover { background-color: #e5e5e5; } ``` JavaScript 文件: ```javascript new Vue({ el: '#app', data: { originalImage: 'original.jpg', // 原始图片路径 modifiedImage: 'modified.jpg', // 修改后的图片路径 diffPoints: [], // 差异点坐标数组 showDiff: false, // 是否显示修改后的图片 score: 0, // 得分 time: 0, // 时间 gameOver: false // 是否游戏结束 }, methods: { checkDiff() { // 使用 pixelmatch 库比对图片 const img1 = new Image(); const img2 = new Image(); const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); img1.onload = () => { canvas.width = img1.width; canvas.height = img1.height; ctx.drawImage(img1, 0, 0); img2.onload = () => { const imgData1 = ctx.getImageData(0, 0, img1.width, img1.height); ctx.drawImage(img2, 0, 0); const imgData2 = ctx.getImageData(0, 0, img2.width, img2.height); const diff = new Uint8ClampedArray(img1.width * img1.height * 4); const diffCount = pixelmatch(imgData1.data, imgData2.data, diff, img1.width, img1.height, {threshold: 0.1}); const diffPoints = []; for (let i = 0; i < diffCount; i++) { const x = (diff[i * 4] + diff[i * 4 + 1] * img1.width) * 4; const y = diff[i * 4 + 2]; diffPoints.push({x, y}); } this.diffPoints = diffPoints; this.score += diffCount * 10; if (diffCount === 0) { // 游戏结束 this.gameOver = true; clearInterval(this.timer); } }; img2.src = this.modifiedImage; }; img1.src = this.originalImage; }, restartGame() { // 重新开始游戏 this.diffPoints = []; this.showDiff = false; this.score = 0; this.time = 0; this.gameOver = false; this.timer = setInterval(() => { this.time++; }, 1000); } }, mounted() { // 开始游戏 this.restartGame(); } }); ``` 注意:上述代码需要引入 pixelmatch 库,可以通过 npm 安装或者直接下载并引入。另外,示例代码中使用的图片路径需要根据实际情况修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值