肥仔教程网

SEO 优化与 Web 开发技术学习分享平台

鸿蒙开发(三十三):Column(鸿蒙 开发平台)

Column 是一个沿垂直方向布局的容器。

例如:

@Entry
@Component
export struct Index {
  build() {
    Column() {
      Text('1')
        .width(100)
        .height(50)
        .backgroundColor(Color.Pink)

      Text('2')
        .width(100)
        .height(50)
        .backgroundColor(Color.Pink)

      Text('3')
        .width(100)
        .height(50)
        .backgroundColor(Color.Pink)
    }
    .width('100%')
    .height('100%')
  }
}

鸿蒙开发入门-UI开发之线性布局Row详解

线性布局方式LinearLayout是在开发中一种比较常用的布局方式,是指通过横向或者是纵向的方式来对页面进行布局的方式,在HarmonyOS UI中提供了Row和Clumn两种线性容器来支持线性布局方式。下面我们就来详细介绍一下两种布局方式。

鸿蒙Next仓颉语言开发实战教程:聊天页面

大家下午好。昨天分享了消息列表页面,今天继续分享聊天页面的开发过程:

这个页面又是常见的上中下布局,从上至下依次为导航栏、聊天列表和输入框工具栏,我们可以先写一下简单的结构,最上面导航栏是横向布局,所以写个Row容器,中间是List,底部仍然是Row容器,导航栏和底部输入框的高度是固定的,List不确定,所以给List设置layoutWeight属性它自动撑满屏幕,具体代码是这样的:

双色球随机筛选红球和蓝球程序,帮助您获得大奖。

复制以下内容至文本文件,修改文件后缀txt为html,即可使用。

<!DOCTYPE html>

<html lang="zh-CN">

HarmonyOS NEXT仓颉开发语言实战案例:小而美的旅行App

大家周末好,本文分享一个小而美的旅行app首页,效果图如下:

很显然这个页面还是使用List容器,页面两侧有统一的边距,我们可以在List容器统一设置:

List(space:20){
}
.padding(left:14,right:14,top:62)
.width(100.percent)
.height(100.percent)
.backgroundColor(0xF6F9FF)

用canvas实现一个头像上的间断式的能量条

今天遇到一个很有意思的面试题,面试官给我一道题目,要我实现之前它们公司之前写的一个组件。

首先我介绍下这道题,首先我是先想到用 flex 布局来写头像分布,因为 grid 布局不能实现头像最后一排不能居中的效果。

有趣的css - 流光圆形按钮(css流星)

网页设计中的CSS(网页设计中的网页界面栅格化是指)

CSS(Cascading Style Sheets)即层叠样式表,是用于美化网页、控制网页布局和外观的语言。以下从基础概念、选择器、常用属性、样式表引入方式和示例代码等方面为你介绍如何用CSS进行网页设计。


基础概念


CSS通过选择器选中HTML元素,然后为这些元素应用样式规则,以改变元素的外观和布局。样式规则由选择器和声明块组成,声明块中包含一个或多个声明,每个声明由属性和值组成,中间用冒号分隔,声明之间用分号分隔。例如:

「干货」9个最热门React PC端组件库|UI框架

最近一直在使用React.js开发项目,在开发过程中也用到了一些开源UI组件库。上次有给大家分享React移动端组件库,今天,就给大家推荐9个常用React PC端组件库。

3 分钟!AI 从零开发五子棋全过程曝光,网友:这效率我服了

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>优雅五子棋</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }
        
        .container {
            max-width: 800px;
            width: 100%;
            margin: 0 auto;
            text-align: center;
        }
        
        h1 {
            color: #2c3e50;
            margin-bottom: 30px;
            font-size: 2.5rem;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
        }
        
        .game-info {
            display: flex;
            justify-content: space-between;
            width: 480px;
            margin: 0 auto 20px;
            font-size: 1.2rem;
            color: #34495e;
        }
        
        .player-info {
            padding: 10px 20px;
            border-radius: 30px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        
        .black {
            background-color: #2c3e50;
            color: white;
        }
        
        .white {
            background-color: #ecf0f1;
            color: #2c3e50;
            border: 1px solid #bdc3c7;
        }
        
        .active {
            transform: translateY(-5px);
            box-shadow: 0 8px 15px rgba(0,0,0,0.2);
        }
        
        .board {
            display: grid;
            grid-template-columns: repeat(15, 32px);
            grid-template-rows: repeat(15, 32px);
            gap: 0;
            margin: 0 auto;
            background-color: #e8bb6e;
            border: 2px solid #8d6e3a;
            box-shadow: 0 10px 20px rgba(0,0,0,0.2);
            border-radius: 4px;
            position: relative;
        }
        
        .cell {
            width: 32px;
            height: 32px;
            position: relative;
            cursor: pointer;
        }
        
        .cell::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            width: 100%;
            height: 1px;
            background-color: #8d6e3a;
            z-index: 1;
        }
        
        .cell::after {
            content: '';
            position: absolute;
            left: 50%;
            top: 0;
            width: 1px;
            height: 100%;
            background-color: #8d6e3a;
            z-index: 1;
        }
        
        .piece {
            position: absolute;
            width: 28px;
            height: 28px;
            border-radius: 50%;
            top: 2px;
            left: 2px;
            z-index: 2;
            box-shadow: 0 3px 5px rgba(0,0,0,0.3);
            transition: transform 0.2s;
        }
        
        .piece.black {
            background-color: #2c3e50;
            background: radial-gradient(circle at 30% 30%, #34495e, #2c3e50);
        }
        
        .piece.white {
            background-color: #ecf0f1;
            background: radial-gradient(circle at 30% 30%, #ffffff, #bdc3c7);
        }
        
        .piece.last-move {
            box-shadow: 0 0 0 2px #e74c3c, 0 3px 5px rgba(0,0,0,0.3);
        }
        
        .controls {
            margin-top: 30px;
        }
        
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 12px 24px;
            font-size: 1rem;
            border-radius: 30px;
            cursor: pointer;
            margin: 0 10px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        
        button:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0,0,0,0.15);
        }
        
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            z-index: 100;
            justify-content: center;
            align-items: center;
        }
        
        .modal-content {
            background-color: white;
            padding: 40px;
            border-radius: 10px;
            text-align: center;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            max-width: 400px;
            width: 90%;
        }
        
        .modal h2 {
            color: #2c3e50;
            margin-bottom: 20px;
        }
        
        .modal button {
            margin-top: 20px;
        }
        
        @media (max-width: 600px) {
            .board {
                grid-template-columns: repeat(15, 20px);
                grid-template-rows: repeat(15, 20px);
            }
            
            .cell {
                width: 20px;
                height: 20px;
            }
            
            .piece {
                width: 18px;
                height: 18px;
                top: 1px;
                left: 1px;
            }
            
            .game-info {
                width: 300px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>优雅五子棋</h1>
        
        <div class="game-info">
            <div class="player-info black active" id="black-info">黑棋回合</div>
            <div class="player-info white" id="white-info">白棋</div>
        </div>
        
        <div class="board" id="board"></div>
        
        <div class="controls">
            <button id="restart-btn">重新开始</button>
            <button id="undo-btn">悔棋</button>
        </div>
    </div>
    
    <div class="modal" id="win-modal">
        <div class="modal-content">
            <h2 id="winner-message">黑棋获胜!</h2>
            <button id="play-again-btn">再玩一局</button>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const board = document.getElementById('board');
            const blackInfo = document.getElementById('black-info');
            const whiteInfo = document.getElementById('white-info');
            const restartBtn = document.getElementById('restart-btn');
            const undoBtn = document.getElementById('undo-btn');
            const winModal = document.getElementById('win-modal');
            const winnerMessage = document.getElementById('winner-message');
            const playAgainBtn = document.getElementById('play-again-btn');
            
            const BOARD_SIZE = 15;
            let currentPlayer = 'black';
            let gameBoard = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null));
            let gameOver = false;
            let moveHistory = [];
            
            // 初始化棋盘
            function initBoard() {
                board.innerHTML = '';
                
                for (let i = 0; i < BOARD_SIZE; i++) {
                    for (let j = 0; j < BOARD_SIZE; j++) {
                        const cell = document.createElement('div');
                        cell.className = 'cell';
                        cell.dataset.row = i;
                        cell.dataset.col = j;
                        cell.addEventListener('click', handleCellClick);
                        board.appendChild(cell);
                    }
                }
            }
            
            // 处理点击事件
            function handleCellClick(e) {
                if (gameOver) return;
                
                const row = parseInt(e.target.dataset.row);
                const col = parseInt(e.target.dataset.col);
                
                if (gameBoard[row][col] !== null) return;
                
                placePiece(row, col);
                
                if (checkWin(row, col)) {
                    gameOver = true;
                    const winner = currentPlayer === 'black' ? '黑棋' : '白棋';
                    winnerMessage.textContent = `${winner}获胜!`;
                    winModal.style.display = 'flex';
                } else {
                    currentPlayer = currentPlayer === 'black' ? 'white' : 'black';
                    updatePlayerInfo();
                }
            }
            
            // 放置棋子
            function placePiece(row, col) {
                gameBoard[row][col] = currentPlayer;
                moveHistory.push({ row, col, player: currentPlayer });
                
                const cell = document.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`);
                const piece = document.createElement('div');
                piece.className = `piece ${currentPlayer}`;
                
                // 移除上一个棋子的last-move类
                const lastMove = document.querySelector('.last-move');
                if (lastMove) {
                    lastMove.classList.remove('last-move');
                }
                
                piece.classList.add('last-move');
                cell.appendChild(piece);
                
                // 添加动画效果
                piece.style.transform = 'scale(0)';
                setTimeout(() => {
                    piece.style.transform = 'scale(1)';
                }, 10);
            }
            
            // 检查获胜
            function checkWin(row, col) {
                const directions = [
                    [0, 1],  // 水平
                    [1, 0],  // 垂直
                    [1, 1],  // 对角线
                    [1, -1]  // 反对角线
                ];
                
                const player = gameBoard[row][col];
                
                for (const [dx, dy] of directions) {
                    let count = 1;
                    
                    // 正向检查
                    for (let i = 1; i < 5; i++) {
                        const newRow = row + i * dx;
                        const newCol = col + i * dy;
                        
                        if (newRow < 0 || newRow >= BOARD_SIZE || newCol < 0 || newCol >= BOARD_SIZE || gameBoard[newRow][newCol] !== player) {
                            break;
                        }
                        
                        count++;
                    }
                    
                    // 反向检查
                    for (let i = 1; i < 5; i++) {
                        const newRow = row - i * dx;
                        const newCol = col - i * dy;
                        
                        if (newRow < 0 || newRow >= BOARD_SIZE || newCol < 0 || newCol >= BOARD_SIZE || gameBoard[newRow][newCol] !== player) {
                            break;
                        }
                        
                        count++;
                    }
                    
                    if (count >= 5) {
                        return true;
                    }
                }
                
                return false;
            }
            
            // 更新玩家信息显示
            function updatePlayerInfo() {
                if (currentPlayer === 'black') {
                    blackInfo.classList.add('active');
                    whiteInfo.classList.remove('active');
                } else {
                    blackInfo.classList.remove('active');
                    whiteInfo.classList.add('active');
                }
            }
            
            // 重新开始游戏
            function restartGame() {
                gameBoard = Array(BOARD_SIZE).fill().map(() => Array(BOARD_SIZE).fill(null));
                currentPlayer = 'black';
                gameOver = false;
                moveHistory = [];
                updatePlayerInfo();
                initBoard();
                winModal.style.display = 'none';
            }
            
            // 悔棋
            function undoMove() {
                if (moveHistory.length === 0 || gameOver) return;
                
                const lastMove = moveHistory.pop();
                gameBoard[lastMove.row][lastMove.col] = null;
                
                const cell = document.querySelector(`.cell[data-row="${lastMove.row}"][data-col="${lastMove.col}"]`);
                const piece = cell.querySelector('.piece');
                if (piece) {
                    piece.remove();
                }
                
                // 更新最后一个棋子的样式
                const newLastMove = moveHistory[moveHistory.length - 1];
                if (newLastMove) {
                    const newCell = document.querySelector(`.cell[data-row="${newLastMove.row}"][data-col="${newLastMove.col}"]`);
                    const newPiece = newCell.querySelector('.piece');
                    if (newPiece) {
                        newPiece.classList.add('last-move');
                    }
                }
                
                currentPlayer = lastMove.player;
                updatePlayerInfo();
            }
            
            // 事件监听
            restartBtn.addEventListener('click', restartGame);
            undoBtn.addEventListener('click', undoMove);
            playAgainBtn.addEventListener('click', restartGame);
            
            // 初始化游戏
            initBoard();
        });
    </script>
</body>
</html>
<< 1 2 3 > >>
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言