jquery ui中 accordion的问题及我的解决方法
原文:jquery ui中 accordion的问题及我的解决方法
jquery有一套所谓的ui组件,很不错的。如果有兴趣的朋友,可以参考http://jqueryui.com/
但其中的accordion,我使用的时候发现一些问题。如果按照demo那样,写一些静态内容,倒也正常。但如果每个面板里面的内容是动态绑定的,则会发生高度变小,然后出现滚动条的诡异现象
- <%@ Page Language="C#" %>
- <%@ Import Namespace="System.Linq" %>
- <%@ Import Namespace="System.Xml.Linq" %>
- <script runat="server">
- protected override void OnPreInit(EventArgs e)
- {
- rp.ItemDataBound += new RepeaterItemEventHandler(rp_ItemDataBound);
- }
- void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
- {
- Label lb = e.Item.FindControl("categoryId") as Label;
- if (lb != null)
- {
- string id = lb.Text;
- var forms = from x in config.Root.Descendants("Form")
- where x.Attribute("CategoryId").Value == id
- select new
- {
- FormTitle = x.Attribute("Title").Value,
- FormDescription = x.Attribute("Description").Value,
- Url = x.Attribute("Url").Value,
- Icon = "Forms/Icons/" + x.Attribute("Icon").Value
- };
- Repeater temp = e.Item.FindControl("rp_forms") as Repeater;
- temp.DataSource = forms;
- temp.DataBind();
- }
- }
- protected override void OnLoad(EventArgs e)
- {
- if (!IsPostBack)
- DataBind();
- }
- private XDocument config = null;
- public override void DataBind()
- {
- //先读取分类数据
- config = XDocument.Load(Server.MapPath("Forms/Forms.xml"));
- var categories = from x in config.Root.Descendants("Category")
- orderby x.Attribute("Id").Value
- select new
- {
- Title = x.Attribute("Title").Value,
- Id = x.Attribute("Id").Value,
- Description = x.Attribute("Description").Value
- };
- rp.DataSource = categories;
- rp.DataBind();
- }
- </script>
- <html>
- <head runat="server">
- <script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
- <script src="ui/ui.core.js" type="text/javascript"></script>
- <script src="ui/ui.accordion.js" type="text/javascript"></script>
- <link href="themes/cupertino/ui.all.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript">
- $(function() {
- $("#formscontainer").accordion();
- });
- </script>
- <style type="text/css">
- li.formli
- {
- list-style-type: none;
- width: 300px;
- float: left;
- }
- li.formli img
- {
- border: none;
- }
- </style>
- </head>
- <body>
- <h2>
- 表单中心</h2>
- <p>
- 这里将列出了所有的表单,您可以通过这里进行表单填写</p>
- <div id="formscontainer">
- <asp:Repeater ID="rp" runat="server">
- <ItemTemplate>
- <h3>
- <a href="#" title='<%# Eval("Description") %>'>
- <%# Eval("Title") %></a>
- <asp:Label ID="categoryId" runat="server" Text='<%# Eval("Id") %>' Visible="false"></asp:Label>
- </h3>
- <div class="details">
- <asp:Repeater ID="rp_forms" runat="server">
- <HeaderTemplate>
- <ul>
- </HeaderTemplate>
- <ItemTemplate>
- <li class="formli">
- <img src='<%# Eval("Icon") %>' />
- <a href='<%# Eval("Url") %>'>
- <%# Eval("FormTitle") %>
- </a>
- <div style="padding-left: 40px">
- <%# Eval("FormDescription") %>
- </div>
- </li>
- </ItemTemplate>
- <FooterTemplate>
- </ul></FooterTemplate>
- </asp:Repeater>
- </div>
- </ItemTemplate>
- </asp:Repeater>
- </div>
- </body>
- </html>
- 开始的时候,看起来不错
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
但只要缩放几次,就会出现下面这样的情况
发现了吗,div的高度会缩小,然后出现滚动条。而且更加神奇的是,它会逐渐变小,小到一定程度之后,又会还原。
尝试过他所有的参数,也没有找到很好的方法,实在也是不解,难道这么明显的问题别人就没有遇到过。
我的解决方法倒也干脆,既然不好用,那就自己动手写一个,其实也没有什么大不了的。当然,我写的这个和accordion不完全一样,但更符合我自己的需要,而且简便易行
脚本代码
- /// 这个脚本用来处理所有的widget行为。
- /// 作者:陈希章
- $(function() {
- $("div.widget").each(function() {
- var w = $(this);
- var d = w.find("div.details");
- var h = parseInt(d.attr("offsetHeight")) + 10;
- d.css("height", h);
- var autoOpen = w.attr("autoOpen");
- if (autoOpen != null && autoOpen == "false") {
- d.fadeOut("fast");
- //只有明确地设置了不自动打开,才隐藏起来
- }
- else {
- //如果设置了一个action,表示要异步加载
- var a = d.attr("action");
- if (a != null) {
- d.empty();
- $("<img src='images/loading.gif' />").appendTo(d);
- d.load(a);
- }
- }
- });
- $("div.widget>div.title").click(function() {
- var t = $(this);
- var d = t.next("div.details");
- t.children(".icon").toggleClass("icon2");
- var display = d.css("display");
- if (display == "none") {
- d.fadeIn("slow", function() {
- var a = d.attr("action");
- if (a != null) {
- d.empty();
- $("<img src='images/loading.gif' />").appendTo(d);
- d.load(a);
- }
- });
- }
- else
- d.fadeOut("fast");
- });
- });
- 页面代码
- <%@ Page Language="C#" %>
- <%@ Import Namespace="System.Linq" %>
- <%@ Import Namespace="System.Xml.Linq" %>
- <script runat="server">
- protected override void OnPreInit(EventArgs e)
- {
- rp.ItemDataBound += new RepeaterItemEventHandler(rp_ItemDataBound);
- }
- void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
- {
- Label lb = e.Item.FindControl("categoryId") as Label;
- if (lb != null)
- {
- string id = lb.Text;
- var forms = from x in config.Root.Descendants("Form")
- where x.Attribute("CategoryId").Value == id
- select new
- {
- FormTitle = x.Attribute("Title").Value,
- FormDescription = x.Attribute("Description").Value,
- Url = x.Attribute("Url").Value,
- Icon = "Forms/Icons/" + x.Attribute("Icon").Value
- };
- Repeater temp = e.Item.FindControl("rp_forms") as Repeater;
- temp.DataSource = forms;
- temp.DataBind();
- }
- }
- protected override void OnLoad(EventArgs e)
- {
- if (!IsPostBack)
- DataBind();
- }
- private XDocument config = null;
- public override void DataBind()
- {
- //先读取分类数据
- config = XDocument.Load(Server.MapPath("Forms/Forms.xml"));
- var categories = from x in config.Root.Descendants("Category")
- orderby x.Attribute("Id").Value
- select new
- {
- Title = x.Attribute("Title").Value,
- Id = x.Attribute("Id").Value,
- Description = x.Attribute("Description").Value
- };
- rp.DataSource = categories;
- rp.DataBind();
- }
- </script>
- <html>
- <head id="Head1" runat="server">
- <script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
- <script src="widget.js" type="text/javascript"></script>
- <link href="Style/Widget.css" rel="stylesheet" type="text/css" />
- <style type="text/css">
- li.formli
- {
- list-style-type: none;
- width: 300px;
- float: left;
- }
- li.formli img
- {
- border: none;
- }
- </style>
- </head>
- <body>
- <h2>
- 表单中心</h2>
- <p>
- 这里将列出了所有的表单,您可以通过这里进行表单填写</p>
- <div id="formscontainer">
- <asp:Repeater ID="rp" runat="server">
- <ItemTemplate>
- <div class="widget">
- <div class="title">
- <div class="icon">
- </div>
- <h3>
- <%# Eval("Title") %>
- <asp:Label ID="categoryId" runat="server" Text='<%# Eval("Id") %>' Visible="false"></asp:Label>
- </h3>
- </div>
- <div class="details">
- <asp:Repeater ID="rp_forms" runat="server">
- <HeaderTemplate>
- <ul>
- </HeaderTemplate>
- <ItemTemplate>
- <li class="formli">
- <img src='<%# Eval("Icon") %>' />
- <a href='<%# Eval("Url") %>'>
- <%# Eval("FormTitle") %>
- </a>
- <div style="padding-left:40px">
- <%# Eval("FormDescription") %>
- </div>
- </li>
- </ItemTemplate>
- <FooterTemplate>
- </ul></FooterTemplate>
- </asp:Repeater>
- </div>
- </div>
- </ItemTemplate>
- </asp:Repeater>
- </div>
- <div class="widget" autoOpen="false">
- <div class="title">
- <div class="icon">
- </div>
- <h3>
- 异步加载的内容
- </h3>
- </div>
- <div class="details" action="AsyncDataPage.aspx">
- </div>
- </div>
- </body>
- </html>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
页面效果
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
点击“异步加载的内容”
jquery ui中 accordion的问题及我的解决方法的更多相关文章
- jquery ui中的dialog,官网上经典的例子
jquery ui中的dialog,官网上经典的例子 jquery ui中dialog和easy ui中的dialog很像,但是最近用到的时候全然没有印象,一段时间不用就忘记了,这篇随笔介绍一下这 ...
- JQuery UI中的Tabs与base元素摩擦的BUG
JQuery UI中的Tabs与base元素冲突的BUG 以前一直使用jquery-ui-1.8,最近打算试一下目前最新的版本1.11.但对于Tabs,页面是乱的,怎么也不正常.折腾了好几个小时,最后 ...
- ASP.NET MVC中对Model进行分步验证的解决方法
原文:ASP.NET MVC中对Model进行分步验证的解决方法 在我之前的文章:ASP.NET MVC2.0结合WF4.0实现用户多步注册流程中将一个用户的注册分成了四步,而这四个步骤都是在完善一个 ...
- 如何自定义JSTL标签与SpringMVC 标签的属性中套JSTL标签报错的解决方法
如何自定义JSTL标签 1.创建一个类,从SimpleTagSupport继承 A) 通过继承可以获得当前JSP页面上的对象,如JspContext I) 实际上可以强转为PageContext II ...
- WAMP中phpMyAdmin登陆不了问题的解决方法
WAMP中phpMyAdmin登陆不了问题的解决方法
- [转载][jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
参考 [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法 ---------------------------------------- ...
- 问题-[Access]“无法打开工作组信息文件中的表 'MSysAccounts'”的问题的解决方法
问题现象:ado.net oledb方式访问Access数据库文件时报错“无法打开工作组信息文件中的表 'MSysAccounts'”的问题的解决方法 问题处理:1.数据库名称不能命名为:Syste ...
- [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法
最近把一个项目的jQuery升级到最新版,发现有些页面报错Cannot read property ‘msie’ of undefined.上jQuery网站上搜了一下,原因是$.browser这个a ...
- jquery升级到新版本报错[jQuery] Cannot read property ‘msie’ of undefined错误的解决方法(转)
最近把一个项目的jQuery升级到最新版,发现有些页面报错Cannot read property 'msie' of undefined.上jQuery网站上搜了一下,原因是$.browser这个a ...
随机推荐
- check————身份证
-- Access 不支持 Substring 查询,可以替换为 mid 查询. select 序号,姓名,身份证号,性别from 身份表where (len(身份证号)<>15 and ...
- 【linux】开发环境说明
欢迎转载,转载时请保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http:// ...
- Eclipse用法和技巧十:显示代码outline
在一个文件中快速找到某一个方法或者某一个作用域,可以使用 Ctrl+O或者Ctrl+F3,快速显示当前代码的outline,进行快速查找.效果如下: 这里主要是补充一些后续操作,能更加方 ...
- Nginx 负载均衡配置和策略
Nginx 的 HttpUpstreamModule 提供对后端(backend)server的简单负载均衡.一个最简单的 upstream 写法例如以下: upstream backend { se ...
- 10个优秀的 HTML5 & CSS3 下拉菜单制作教程
下拉菜单是一个非经常见的效果.在站点设计中被广泛使用.通过使用下拉菜单.设计者不仅能够在站点设计中营造出色的视觉吸引力,但也能够为站点提供了一个有效的导航方案.使用 HTML5 和 CSS3 能够更e ...
- Selenium Webdriver firefox 浏览器问题
Selenium Webdriver 在使用firefox 测试会牵扯到firefox的安装路径的问题 1.默认安装路径在c盘的情况下: WebDriver driver = new FirefoxD ...
- bestcoder.hdu.edu.cn
http://bestcoder.hdu.edu.cn/ Problem A 题目链接: http://bestcoder.hdu.edu.cn/contests/contest_showproble ...
- Win32环境下的程序崩溃异常定位
1 案例描述 作为Windows程序员,平时最担心见到的事情可能就是程序发生了崩溃(异常),这时Windows会提示该程序执行了非法操作,即将关闭.请与您的供应商联系.呵呵,这句微软的“名 ...
- Eclipse代码字体、颜色美化,更改字体大小、颜色
先看效果: 感觉如何,是否比你的eclipse编辑器显示的代码要漂亮简洁呢?呵呵.这个是我原来ADT Eclipse的效果,现在去下居然更新掉了,找不到了.于是我就参照我原来的配置对这个新的Eclip ...
- 在ListView中实现排序
此处介绍的情境是: (1)使用table布局ListView. (2)ListView的数据源是List<T>. (3)排序字段2个(帖子的回复次数和浏览次数),都是int类型. 基本思路 ...