【HTML网页制作实例】HTML网页应用,用于显示一个“Pokedex”(来自Pokemon系列的怪物图鉴)

这段代码是一个简单的网页应用,用于显示一个“Pokedex”(来自Pokemon系列的怪物图鉴)。下面是代码的分析和解释:

HTML结构

  • <html>: 定义HTML文档的根元素。
  • <head>: 包含文档的元数据,如字符集、视口设置、样式和标题。
  • <body>: 包含主要的页面内容,包括标题和一个用于显示Pokemon卡片的容器。

CSS样式

  • * { box-sizing: border-box; }: 确保所有元素的padding和border都包含在元素的总宽度和高度内。
  • body: 设置了背景渐变、字体、布局方式(flex)以及居中对齐。
  • h1: 增加了字母间距。
  • .poke-container: 设置为flex容器,用于包裹所有的Pokemon卡片,支持换行和居中对齐。
  • .pokemon: 定义了每个Pokemon卡片的样式,包括背景色、圆角、阴影、边距和填充。
  • .img-container 和 img: 定义了图片容器的样式和图片的最大宽度。
  • .info.number.name: 定义了Pokemon信息的样式,如编号、名字和类型的展示方式。

JavaScript功能

  • 变量定义:
    • poke_container: 获取页面中用于放置Pokemon卡片的容器。
    • pokemon_count: 定义了要显示的Pokemon总数(150个)。
    • colors: 一个对象,存储了不同Pokemon类型对应的颜色。
    • main_types: 获取colors对象的所有键,即Pokemon的所有类型。
  • 函数:
    • fetchPokemons: 异步函数,循环调用getPokemon函数以获取每个Pokemon的数据。
    • getPokemon: 异步函数,用于从API获取特定id的Pokemon数据。这里的url变量为空,需要填写正确的API URL。
    • createPokemonCard: 根据获取到的Pokemon数据创建一个卡片,并添加到页面上。这个函数处理了名字的首字母大写、编号的格式化、类型的颜色匹配以及HTML结构的创建。
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <style>
          * {
              box-sizing: border-box;
          }

          body {
              background: #efefbb;
              background: linear-gradient(to right, #d4d3dd, #efefbb);
              font-family: 'Lato', sans-serif;
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
              margin: 0;
          }

          h1 {
              letter-spacing: 3px;
          }

          .poke-container {
              display: flex;
              flex-wrap: wrap;
              align-items: space-between;
              justify-content: center;
              margin: 0 auto;
              max-width: 1200px;
          }

          .pokemon {
              background-color: #eee;
              border-radius: 10px;
              box-shadow: 0 3px 15px rgba(100, 100, 100, 0.5);
              margin: 10px;
              padding: 20px;
              text-align: center;
          }

              .pokemon .img-container {
                  background-color: rgba(255, 255, 255, 0.6);
                  border-radius: 50%;
                  width: 120px;
                  height: 120px;
                  text-align: center;
              }

                  .pokemon .img-container img {
                      max-width: 90%;
                      margin-top: 20px;
                  }

              .pokemon .info {
                  margin-top: 20px;
              }

                  .pokemon .info .number {
                      background-color: rgba(0, 0, 0, 0.1);
                      padding: 5px 10px;
                      border-radius: 10px;
                      font-size: 0.8em;
                  }

                  .pokemon .info .name {
                      margin: 15px 0 7px;
                      letter-spacing: 1px;
                  }

      </style>
    <title>Pokedex</title>
  </head>
  <body>
    <h1>Pokedex</h1>
    <div class="poke-container" id="poke-container"></div>

    <!-- Design inspired by this Dribbble shot: https://dribbble.com/shots/5611109--Pokemon -->
    <script>
        const poke_container = document.getElementById('poke-container')
        const pokemon_count = 150
        const colors = {
            fire: '#FDDFDF',
            grass: '#DEFDE0',
            electric: '#FCF7DE',
            water: '#DEF3FD',
            ground: '#f4e7da',
            rock: '#d5d5d4',
            fairy: '#fceaff',
            poison: '#98d7a5',
            bug: '#f8d5a3',
            dragon: '#97b3e6',
            psychic: '#eaeda1',
            flying: '#F5F5F5',
            fighting: '#E6E0D4',
            normal: '#F5F5F5'
        }

        const main_types = Object.keys(colors)

        const fetchPokemons = async () => {
            for (let i = 1; i <= pokemon_count; i++) {
                await getPokemon(i)
            }
        }

        const getPokemon = async (id) => {
            const url = `https://pokeapi.co/api/v2/pokemon/${id}`
            const res = await fetch(url)
            const data = await res.json()
            createPokemonCard(data)
        }

        const createPokemonCard = (pokemon) => {
            const pokemonEl = document.createElement('div')
            pokemonEl.classList.add('pokemon')

            const name = pokemon.name[0].toUpperCase() + pokemon.name.slice(1)
            const id = pokemon.id.toString().padStart(3, '0')

            const poke_types = pokemon.types.map(type => type.type.name)
            const type = main_types.find(type => poke_types.indexOf(type) > -1)
            const color = colors[type]

            pokemonEl.style.backgroundColor = color

            const pokemonInnerHTML = `
    <div class="img-container">
        <img src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png"" alt="${name}">
    </div>
    <div class="info">
        <span class="number">#${id}</span>
        <h3 class="name">${name}</h3>
        <small class="type">Type: <span>${type}</span> </small>
    </div>
    `

            pokemonEl.innerHTML = pokemonInnerHTML

            poke_container.appendChild(pokemonEl)
        }

        fetchPokemons()

    </script>
  </body>
</html>

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值