positon之relative.

背景介绍:

画面(容器)由上到下有header,toolBar,body,footer四个区域,

1.画面的高度固定;

2.header, footer,toolBar高度可变,比如:默认height: 30px;可是内部元素

增加后需要"换行",所以高度会增加。

3.body的高度随之改变。即: 画面height - header height - toolBar height - footer Height;

 

关键点: 

整个画面(容器)及其子元素 采用 相对定位, 需要合理设置内部元素的高度来"撑满"画面。

即: 只需要将 body区域的高度设置正确,整个画面的高度就正确了。

 

ps: 如果用绝对定位的话,我认为相对麻烦。

 

补充:

采用JQuery来获取元素高度,

$(selector).height();

$(selector).innerHeight();// 包括padding

$(selector).outerHeight();// 包括padding, border

$(selector).outerHeight(true);// 包括padding, border, margin

 

 

 

import os import sys import time import pygame import random WIDTH = 500 HEIGHT = 500 NUMGRID = 8 GRIDSIZE = 50 XMARGIN= (WIDTH - GRIDSIZE * NUMGRID) //2 YMARGIN = (HEIGHT - GRIDSIZE * NUMGRID) // 2 x_animal=XMARGIN y_animal=YMARGIN ROOTDIR = os.getcwd() FPS = 100 clock=pygame.time.Clock() pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('消消乐') screen.fill((255, 255, 220)) path_list=[] # 游戏界面的网格绘制 def drawBlock(block, color=(255, 0, 0), size=2): pygame.draw.rect(screen, color, block, size) for x in range(NUMGRID): for y in range(NUMGRID): rect = pygame.Rect((XMARGIN + x * GRIDSIZE, YMARGIN + y * GRIDSIZE, GRIDSIZE, GRIDSIZE)) drawBlock(rect, color=(255, 165, 0), size=1) class animal(pygame.sprite.Sprite): def __init__(self,screen): pygame.sprite.Sprite.__init__(self) self.screen=screen im_path = os.listdir('source') path_list.append([]) global x_animal global y_animal self.positon_rect = pygame.Rect((x_animal,y_animal, GRIDSIZE, GRIDSIZE)) path = random.choice(im_path) self.image = pygame.image.load('source/' + path) self.rect = self.image.get_rect() screen.blit(self.image, (self.positon_rect.x + 1,self.positon_rect.y)) y_animal+=GRIDSIZE if y_animal>8*GRIDSIZE: x_animal=x_animal+GRIDSIZE y_animal=YMARGIN def move(self): for i in range(50): screen.fill((255, 255, 220)) for x in range(NUMGRID): for y in range(NUMGRID): rect = pygame.Rect((XMARGIN + x * GRIDSIZE, YMARGIN + y * GRIDSIZE, GRIDSIZE, GRIDSIZE)) drawBlock(rect, color=(255, 165, 0), size=1) for i in range(64): screen.blit(animal_d['animal'+str(i)].image,animal_d['animal'+str(i)].positon_rect) self.positon_rect.move_ip(1,0) screen.blit(self.image,self.positon_rect)
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值