[前端]使用JQuery UI Layout Plug-in布局 - wolfy

引言

使用JQuery UI Layout Plug-in布局框架实现快速布局,用起来还是挺方便的,稍微研究了一下,就能上手,关于该布局框架的材料,网上也挺多的。在项目中也使用到了,不过那是前端的工作,咱不能抢别人的饭碗不是?,不过对布局多少了解点,还是非常有帮助的。

实现

JQuery UI Layout Plug-in布局框架官网: http://layout.jquery-dev.net/index.cfm

这里使用1.2.0版本的,项目结构:

首先引入:

1  <script type="text/javascript" src="Layout/jquery.js"></script> 2 <script type="text/javascript" src="Layout/jquery.layout.js"></script>

body中代码:

1 <div class="ui-layout-center">
2         Center
3     </div> 4 <div class="ui-layout-north">North</div> 5 <div class="ui-layout-south">South</div> 6 <!--<div class="ui-layout-east">East</div>--> 7 <div class="ui-layout-west">West</div>

然后就是使用layout方法进行初始化:

 1     <script type="text/javascript"> 2 $(function () { 3 var myLayout = $("body").layout( 4 { 5 applyDefaultStyles: true,//应用默认样式 6 scrollToBookmarkOnLoad: false,//页加载时滚动到标签 7 showOverflowOnHover: false,//鼠标移过显示被隐藏的,只在禁用滚动条时用。 8 north__closable: false,//可以被关闭 9 north__resizable: false,//可以改变大小 10 north__size: 50,//pane的大小 11 spacing_open: 8,//边框的间隙 12 spacing_closed: 60,//关闭时边框的间隙 13 resizerTip: "可调整大小",//鼠标移到边框时,提示语 14 resizerCursor:"resize-p",// 鼠标移上的指针样式 15 resizerDragOpacity: 0.9,//调整大小边框移动时的透明度 16 maskIframesOnResize: "#ifa",//在改变大小的时候,标记iframe(未通过测试) 17 sliderTip: "显示/隐藏侧边栏",//在某个Pane隐藏后,当鼠标移到边框上显示的提示语。 18 sliderCursor: "pointer",//在某个Pane隐藏后,当鼠标移到边框上时的指针样式。 19 slideTrigger_open: "dblclick",//在某个Pane隐藏后,鼠标触发其显示的事件。(click", "dblclick", "mouseover) 20 slideTrigger_close: "click",//在某个Pane隐藏后,鼠标触发其关闭的事件。("click", "mouseout") 21 togglerTip_open: "关闭",//pane打开时,当鼠标移动到边框上按钮上,显示的提示语 22 togglerTip_closed: "打开",//pane关闭时,当鼠标移动到边框上按钮上,显示的提示语 23 togglerLength_open: 100,//pane打开时,边框按钮的长度 24 togglerLength_closed: 200,//pane关闭时,边框按钮的长度 25 hideTogglerOnSlide: true,//在边框上隐藏打开/关闭按钮(测试未通过) 26 togglerAlign_open: "left",//pane打开时,边框按钮显示的位置 27 togglerAlign_closed: "right",//pane关闭时,边框按钮显示的位置 28 togglerContent_open: "<div style='background:red'>AAA</div>",//pane打开时,边框按钮中需要显示的内容可以是符号"<"等。需要加入默认css样式.ui-layout-toggler .content 29 togglerContent_closed: "<img/>",//pane关闭时,同上。 30 enableCursorHotkey: true,//启用快捷键CTRL或shift + 上下左右。 31 customHotkeyModifier: "shift",//自定义快捷键控制键("CTRL", "SHIFT", "CTRL+SHIFT"),不能使用alt 32 south__customHotkey: "shift+0",//自定义快捷键(测试未通过) 33 fxName: "drop",//打开关闭的动画效果 34 fxSpeed: "slow"//动画速度 35 //fxSettings: { duration: 500, easing: "bounceInOut" }//自定义动画设置(未通过测试) 36 //initClosed:true,//初始时,所有pane关闭 37 //initHidden:true //初始时,所有pane隐藏 38 //onresize: ons,//调整大小时调用的函数 39 //onshow_start: start, 40 //onshow_end: end 41 /* 42 其他回调函数 43 44 显示时调用 45 onshow = "" 46 onshow_start = "" 47 onshow_end = "" 48 隐藏时调用 49 onhide = "" 50 onhide_start = "" 51 onhide_end = "" 52 打开时调用 53 onopen = "" 54 onopen_start = "" 55 onopen_end = "" 56 关闭时调用 57 onclose = "" 58 onclose_start = "" 59 onclose_end = "" 60 改变大小时调用 61 onresize = "" 62 onresize_start = "" 63 onresize_end = "" 64 */ 65 } 66 ); 67 68 69 });

参考文章: http://www.cnblogs.com/chen-fan/articles/2044556.html

注意:在将不需要的参数注释之后,需将最后一个参数后面的“,”去掉,经测试发现有的浏览器版本不支持,看不到效果。

将不需要的参数注释之后的效果: 

总结

今天在使用该布局框架的时候,一个逗号问题,折腾我很长时间,这里记录一下,提醒以后要更细心才行。

demo:链接: http://pan.baidu.com/s/1eQd1b5w 密码:m0z5

转载于:https://www.cnblogs.com/yelanggu/p/5284097.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是用 Java 写的狼和羊在地图上的示例代码: ``` import java.util.Random; public class Map { private int width; private int height; private boolean[][] occupied; public Map(int width, int height) { this.width = width; this.height = height; this.occupied = new boolean[width][height]; } public boolean isOccupied(int x, int y) { if (x < 0 || x >= this.width || y < 0 || y >= this.height) { return true; } return this.occupied[x][y]; } public void occupy(int x, int y) { if (x >= 0 && x < this.width && y >= 0 && y < this.height) { this.occupied[x][y] = true; } } public void vacate(int x, int y) { if (x >= 0 && x < this.width && y >= 0 && y < this.height) { this.occupied[x][y] = false; } } } public class Animal { protected int x; protected int y; public Animal(int x, int y) { this.x = x; this.y = y; } public void move(int dx, int dy) { this.x += dx; this.y += dy; } public int getX() { return this.x; } public int getY() { return this.y; } } public class Wolf extends Animal { private int energy; public Wolf(int x, int y) { super(x, y); this.energy = 10; } public void eat(Sheep sheep) { this.energy += sheep.getNutritionValue(); } public boolean isStarving() { return this.energy <= 0; } public void loseEnergy() { this.energy--; } public int getEnergy() { return this.energy; } } public class Sheep extends Animal { private int nutritionValue; public Sheep(int x, int y) { super(x, y); this.nutritionValue = 5; } public int getNutritionValue() { return this.nutritionValue; } } public class Simulation { private Map map; private Wolf wolf; private Sheep sheep; private Random random; public Simulation(int width, int height) { this.map = new Map(width, height); this.random = new Random(); int wolfX = this.random.nextInt(width); int wolfY = this.random.nextInt(height); this.wolf = new Wolf(wolfX, wolfY); this.map.occupy(wolfX, wolfY); int sheepX = this.random.nextInt(width); int sheepY = this.random.nextInt(height); while (this.map.isOccupied(sheepX, sheepY)) { sheepX = this.random.nextInt(width); sheepY = this.random.nextInt(height); } this.sheep = new Sheep(sheepX, sheepY); this.map.occupy(sheepX, sheepY); } public void run() { int time = 0; while (!this.wolf.isStarving()) { time++; System.out.println("Time: " + time); System.out.println("Wolf: (" + this.wolf.getX() + ", " + this.wolf.getY() + "), Energy: " + this.wolf.getEnergy()); System.out.println("Sheep: (" + this.sheep.getX() + ", " + this.sheep.getY() + ")"); int dx = this.random.nextInt(3) - 1; int dy = this.random.nextInt(3) - 1; this.wolf.move(dx, dy); if (this.wolf.getX() == this.sheep.getX() && this.wolf.getY() == this.sheep.getY()) { this.wolf.eat(this.sheep); this.map.vacate(this.sheep.getX(), this.sheep.getY()); int newX = this.random.nextInt(this.map.width); int newY = this.random.nextInt(this.map.height); while (this.map.isOccupied(newX, newY)) { newX = this.random.nextInt(this.map.width); newY = this.random.nextInt(this.map.height); } this.sheep = new Sheep(newX, newY); this.map.occupy(newX, newY); } else { this.wolf.loseEnergy(); } System.out.println("============================================="); } System.out.println("Wolf is starving!"); } } public class Main { public static void main(String[] args) { Simulation simulation = new Simulation(10, 10); simulation.run(); } } ``` 以上代码定义了五个类,`Map`、`Animal`、`Wolf`、`Sheep` 和 `Simulation`。`Map` 类代表地图,有 `width`、`height` 和 `occupied` 三个属性,分别代表宽度、高度和哪些位置被占用了;`Animal` 类代表动物,有 `x` 和 `y` 两个属性,分别代表横坐标和纵坐标;`Wolf` 类继承自 `Animal` 类,有 `energy` 属性,代表能量,还有 `eat`、`isStarving`、`loseEnergy` 和 `getEnergy` 方法,分别代表吃、是否饥饿、消耗能量和获取当前能量值;`Sheep` 类继承自 `Animal` 类,有 `nutritionValue` 属性,代表营养价值,还有 `getNutritionValue` 方法,返回营养价值;`Simulation` 类代表仿真,有 `map`、`wolf`、`sheep` 和 `random` 四个属性,分别代表地图、狼、羊和随机数生成器,还有 `run` 方法,代表运行仿真。 在 `Simulation` 类的构造函数中,会初始化地图、狼和羊。在 `run` 方法中,会循环执行以下操作: 1. 输出当前时间、狼的位置和能量、羊的位置。 2. 随机生成一个移动的方向,并让狼移动。 3. 如果狼和羊在同一个位置,狼吃掉羊,并在地图上移除羊,随机生成一个新的羊,并在地图上放置。 4. 否则,狼消耗能量。 5. 输出分割线。 如果狼的能量小于等于 0,就输出 `Wolf is starving!`。 这只是一个简单的示例,可以根据需要进一步扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值