与<rich:modalPanel />的战斗

本文介绍了一种解决Rich ModalPanel控件在不同浏览器环境下显示问题的方法。通过调整CSS样式及特定IE6的JavaScript代码,实现了当弹出层高度超过浏览器窗口时的适配方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

发自肺腑的说<rich:modalPanel />真是一个不错的弹出层控件
拖动、定位、自动适应大小、手动改变大小 我的需求他都能一一满足

但有些地方也有点人性化过头了 不够灵活
弹出层总是固定(position: fixed)在某个位置上
换句话说 拉动滚动条 弹出层不会跟着上下移动

一般情况下当然没问题 这样也挺好
但当弹出层的高度 > 浏览器的高度后 问题就来了
由于是固定位置 所以超出浏览器的部分就怎么也看不到了
也许控件的作者认为弹出层的内容一定都很短小吧

查看了N遍API 也没发现可以关闭这个"特性"的方法
正规方法的不行 那只能来"硬"的了
过程省略...直接看解决方案吧

[b][color=blue]IE6以外的浏览器[/color][/b]解决方案很简单 只要设置一段CSS样式即可

.rich-mpnl_panel {
position: absolute;
}


但[b][color=blue]IE6[/color][/b]还不行 需要多费些事
查看源代码得知由于IE6不支持position: fixed
所以弹出层固定位置 是使用IE专有的CSS表达式来实现的
具体代码为 modalPanel.js 580行左右

var leftExpr = "(this.mpLeft || 0) + -Position.cumulativeOffset(this.parentNode)[0] + getSizeElement().scrollLeft + \"px\"";
var topExpr = "(this.mpTop || 0) + -Position.cumulativeOffset(this.parentNode)[1] + getSizeElement().scrollTop + \"px\"";

eCdiv.style.setExpression("left", leftExpr);
eCdiv.style.setExpression("top", topExpr);

由于不想修改控件代码(这样会对以后的升级照成麻烦)
所以只能动态的删除针对top的CSS表达式
代码如下

function removeModalPanelTopFixedForIE6(obj)
{
//IE6
if(jQuery.browser.msie && jQuery.browser.version < 7)
{
//ID
var id = obj.id.substring(0, obj.id.indexOf("Container"));
//去除针对IE6高度top的css表达式
jQuery(obj).find("#" + id + "CDiv")[0].style.removeExpression("top");
}
}

然后需要修正这个问题时这样调用

<rich:modalPanel onshow="removeModalPanelTopFixedForIE6(this)">
......
</rich:modalPanel>

完毕... :arrow:
<?xml version="1.0" encoding="utf-8" ?> <Defs> <ThingDef Abstract="True" Name="OrganicProductBase" ParentName="ResourceBase"> <graphicData> <graphicClass>Graphic_Single</graphicClass> </graphicData> <statBases> <MaxHitPoints>60</MaxHitPoints> <Flammability>1.0</Flammability> <DeteriorationRate>6</DeteriorationRate> <Mass>0.03</Mass> </statBases> <tickerType>Rare</tickerType> <healthAffectsPrice>false</healthAffectsPrice> </ThingDef> <ThingDef Abstract="True" Name="PlantFoodRawBase" ParentName="OrganicProductBase"> <ingestible> <preferability>RawBad</preferability> <tasteThought>AteRawFood</tasteThought> <ingestEffect>EatVegetarian</ingestEffect> <ingestSound>RawVegetable_Eat</ingestSound> </ingestible> <statBases> <Nutrition>0.05</Nutrition> <FoodPoisonChanceFixedHuman>0.02</FoodPoisonChanceFixedHuman> </statBases> <socialPropernessMatters>true</socialPropernessMatters> <thingCategories> <li>PlantFoodRaw</li> </thingCategories> <allowedArchonexusCount>200</allowedArchonexusCount> </ThingDef> <ThingDef ParentName="PlantFoodRawBase"> <defName>RawPotatoes</defName> <label>potatoes</label> <description>Raw potatoes.</description> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Potatoes</texPath> </graphicData> <statBases> <MarketValue>1.1</MarketValue> </statBases> <ingestible> <foodType>VegetableOrFruit</foodType> </ingestible> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>30</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> </ThingDef> <ThingDef ParentName="PlantFoodRawBase"> <defName>RawFungus</defName> <label>raw fungus</label> <description>Raw fungus.</description> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/RawFungus</texPath> </graphicData> <statBases> <MarketValue>1.1</MarketValue> </statBases> <ingestible> <foodType>Fungus</foodType> </ingestible> <ingredient> <mergeCompatibilityTags> <li MayRequire="Ludeon.RimWorld.Ideology">Fungus</li> </mergeCompatibilityTags> </ingredient> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>30</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> </ThingDef> <ThingDef ParentName="PlantFoodRawBase"> <defName>RawRice</defName> <label>rice</label> <description>Raw rice.</description> <soundInteract>Grain_Drop</soundInteract> <soundDrop>Grain_Drop</soundDrop> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Rice</texPath> </graphicData> <statBases> <MarketValue>1.1</MarketValue> </statBases> <ingestible> <foodType>Seed</foodType> </ingestible> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>40</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> </ThingDef> <ThingDef ParentName="PlantFoodRawBase"> <defName>RawAgave</defName> <label>agave fruit</label> <description>Raw agave fruit.</description> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/AgaveFruit</texPath> </graphicData> <statBases> <MarketValue>1.1</MarketValue> </statBases> <ingestible> <foodType>VegetableOrFruit</foodType> </ingestible> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>25</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> </ThingDef> <ThingDef ParentName="PlantFoodRawBase"> <defName>RawCorn</defName> <label>corn</label> <description>Raw corn.</description> <soundInteract>Grain_Drop</soundInteract> <soundDrop>Grain_Drop</soundDrop> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Corn</texPath> </graphicData> <statBases> <MarketValue>1.1</MarketValue> </statBases> <ingestible> <foodType>VegetableOrFruit</foodType> </ingestible> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>60</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> </ThingDef> <ThingDef ParentName="PlantFoodRawBase"> <defName>RawBerries</defName> <label>berries</label> <description>Assorted berries. Nice to eat, even when raw.</description> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Berries</texPath> </graphicData> <statBases> <MarketValue>1.2</MarketValue> <Mass>0.027</Mass> </statBases> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>14</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> <ingestible> <preferability>RawTasty</preferability> <tasteThought></tasteThought> <foodType>VegetableOrFruit</foodType> </ingestible> </ThingDef> <!-- Plant matter (inedible by people) --> <ThingDef ParentName="OrganicProductBase" Name="RoughPlantBase" Abstract="True"> <ingestible> <foodType>Plant</foodType> <preferability>DesperateOnlyForHumanlikes</preferability> </ingestible> <statBases> <Nutrition>0.05</Nutrition> </statBases> </ThingDef> <ThingDef ParentName="RoughPlantBase"> <defName>Hay</defName> <label>hay</label> <description>Nutrient-rich grasses and shoots, harvested and compacted for storage. Hay is good animal feed, but inedible for humans.</description> <stackLimit>200</stackLimit> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Hay</texPath> <graphicClass>Graphic_StackCount</graphicClass> </graphicData> <statBases> <MarketValue>0.6</MarketValue> <Mass>0.014</Mass> <Flammability>1.5</Flammability> </statBases> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>60</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> <thingCategories> <li>Foods</li> </thingCategories> <ingestible> <optimalityOffsetFeedingAnimals>7</optimalityOffsetFeedingAnimals> </ingestible> <allowedArchonexusCount>400</allowedArchonexusCount> </ThingDef> <ThingDef ParentName="RoughPlantBase"> <defName>RawHops</defName> <label>hops</label> <description>Raw hops. A flavoring and preserving agent that is necessary for making beer.</description> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Hops</texPath> </graphicData> <statBases> <MarketValue>1.3</MarketValue> </statBases> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>30</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> <thingCategories> <li>PlantMatter</li> </thingCategories> <ingestible> <preferability>DesperateOnly</preferability> <canAutoSelectAsFoodForCaravan>false</canAutoSelectAsFoodForCaravan> </ingestible> </ThingDef> <ThingDef ParentName="RoughPlantBase"> <defName>PsychoidLeaves</defName> <label>psychoid leaves</label> <description>Raw cut leaves of a psychoid plant. Can be refined into various form of the stimulant drug psychite.</description> <possessionCount>10</possessionCount> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/PsychoidLeaves</texPath> </graphicData> <statBases> <MarketValue>1.9</MarketValue> <Flammability>1.3</Flammability> </statBases> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>30</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> <thingCategories> <li>PlantMatter</li> </thingCategories> <ingestible> <preferability>DesperateOnly</preferability> <canAutoSelectAsFoodForCaravan>false</canAutoSelectAsFoodForCaravan> </ingestible> </ThingDef> <ThingDef ParentName="RoughPlantBase"> <defName>SmokeleafLeaves</defName> <label>smokeleaf leaves</label> <description>Raw cut leaves of a smokeleaf plant. Can be rolled into smokeable joints at a crafting spot.</description> <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/SmokeleafLeaves</texPath> </graphicData> <statBases> <MarketValue>1.6</MarketValue> <Flammability>1.3</Flammability> </statBases> <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>30</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> <thingCategories> <li>PlantMatter</li> </thingCategories> <ingestible> <preferability>DesperateOnly</preferability> <canAutoSelectAsFoodForCaravan>false</canAutoSelectAsFoodForCaravan> </ingestible> </ThingDef> </Defs> 逐行解释
最新发布
07-20
这是一个 XML 格式的 `Defs` 文件,用于定义 RimWorld 中的“植物类原材料”(Organic Product)的多个 `ThingDef`,即游戏中的物品定义。这些定义包括生食植物、粗制植物材料等,它们在游戏内作为资源使用。以下是逐行解释: --- ### XML 标记解释 ```xml <?xml version="1.0" encoding="utf-8" ?> ``` - 定义该 XML 文件的版本和编码格式为 UTF-8。 ```xml <Defs> ``` - 开始一个定义块,通常用于 RimWorld 模组中的自定义定义。 --- ### 基础类定义 #### OrganicProductBase(有机产品基础类) ```xml <ThingDef Abstract="True" Name="OrganicProductBase" ParentName="ResourceBase"> ``` - 定义一个抽象类 `OrganicProductBase`,继承自 `ResourceBase`。 ```xml <graphicData> <graphicClass>Graphic_Single</graphicClass> </graphicData> ``` - 图形使用 `Graphic_Single` 类型,表示单一贴图。 ```xml <statBases> <MaxHitPoints>60</MaxHitPoints> <Flammability>1.0</Flammability> <DeteriorationRate>6</DeteriorationRate> <Mass>0.03</Mass> </statBases> ``` - 基础属性:最大耐久 60、可燃性 1.0、劣化率 6、质量 0.03。 ```xml <tickerType>Rare</tickerType> ``` - 更新频率为“稀有”,表示该物品不需要频繁更新。 ```xml <healthAffectsPrice>false</healthAffectsPrice> ``` - 健康状态不影响价格。 --- #### PlantFoodRawBase(生食植物基础类) ```xml <ThingDef Abstract="True" Name="PlantFoodRawBase" ParentName="OrganicProductBase"> ``` - 抽象类 `PlantFoodRawBase`,继承自 `OrganicProductBase`。 ```xml <ingestible> <preferability>RawBad</preferability> <tasteThought>AteRawFood</tasteThought> <ingestEffect>EatVegetarian</ingestEffect> <ingestSound>RawVegetable_Eat</ingestSound> </ingestible> ``` - 可食用属性:生吃效果差、触发 `AteRawFood` 思想、素食效果、食用音效。 ```xml <statBases> <Nutrition>0.05</Nutrition> <FoodPoisonChanceFixedHuman>0.02</FoodPoisonChanceFixedHuman> </statBases> ``` - 营养值 0.05、人类中毒几率 2%。 ```xml <socialPropernessMatters>true</socialPropernessMatters> ``` - 社交礼仪影响是否食用。 ```xml <thingCategories> <li>PlantFoodRaw</li> </thingCategories> ``` - 所属分类为 `PlantFoodRaw`。 ```xml <allowedArchonexusCount>200</allowedArchonexusCount> ``` - 允许在 Archonexus 中出现的最大数量为 200。 --- ### 具体生食植物定义 #### RawPotatoes(生土豆) ```xml <ThingDef ParentName="PlantFoodRawBase"> <defName>RawPotatoes</defName> ``` - 内部名称为 `RawPotatoes`。 ```xml <label>potatoes</label> <description>Raw potatoes.</description> ``` - 显示名称和描述。 ```xml <possessionCount>10</possessionCount> ``` - 默认拥有数量为 10。 ```xml <graphicData> <texPath>Things/Item/Resource/PlantFoodRaw/Potatoes</texPath> </graphicData> ``` - 使用指定贴图路径。 ```xml <statBases> <MarketValue>1.1</MarketValue> </statBases> ``` - 市场价格为 1.1。 ```xml <ingestible> <foodType>VegetableOrFruit</foodType> </ingestible> ``` - 食物类型为蔬菜或水果。 ```xml <comps> <li Class="CompProperties_Rottable"> <daysToRotStart>30</daysToRotStart> <rotDestroys>true</rotDestroys> </li> </comps> ``` - 添加腐烂组件,30 天后开始腐烂,腐烂后销毁。 --- 其余如 `RawFungus`、`RawRice`、`RawAgave`、`RawCorn`、`RawBerries` 的结构 `RawPotatoes` 类似,只是贴图路径、价格、腐烂时间等参数不同。 --- ### 粗制植物材料定义 #### RoughPlantBase(粗制植物基础类) ```xml <ThingDef ParentName="OrganicProductBase" Name="RoughPlantBase" Abstract="True"> ``` - 抽象类 `RoughPlantBase`,继承自 `OrganicProductBase`。 ```xml <ingestible> <foodType>Plant</foodType> <preferability>DesperateOnlyForHumanlikes</preferability> </ingestible> ``` - 仅供绝望时食用,人类不会主动吃。 ```xml <statBases> <Nutrition>0.05</Nutrition> </statBases> ``` - 营养值 0.05。 --- #### Hay(干草) ```xml <ThingDef ParentName="RoughPlantBase"> <defName>Hay</defName> ``` - 内部名称为 `Hay`。 ```xml <description>Nutrient-rich grasses and shoots...</description> ``` - 描述为动物饲料。 ```xml <stackLimit>200</stackLimit> ``` - 最大堆叠数量为 200。 ```xml <graphicData> <graphicClass>Graphic_StackCount</graphicClass> </graphicData> ``` - 使用堆叠贴图类。 ```xml <statBases> <MarketValue>0.6</MarketValue> <Mass>0.014</Mass> <Flammability>1.5</Flammability> </statBases> ``` - 市场价 0.6、质量 0.014、可燃性 1.5。 ```xml <comps> <li Class="CompProperties_Rottable">...</li> </comps> ``` - 添加腐烂组件。 ```xml <thingCategories> <li>Foods</li> </thingCategories> ``` - 所属分类为 `Foods`。 ```xml <ingestible> <optimalityOffsetFeedingAnimals>7</optimalityOffsetFeedingAnimals> </ingestible> ``` - 动物食用时的最优性偏移值为 7。 ```xml <allowedArchonexusCount>400</allowedArchonexusCount> ``` - Archonexus 中最大允许数量为 400。 --- 其余如 `RawHops`、`PsychoidLeaves`、`SmokeleafLeaves` 的结构 `Hay` 类似,但用途不同(如酿酒、制毒、卷烟)。 --- ```xml </Defs> ``` - Defs 块结束。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值