The recent landing Members
Download
当前位置: Sincol.net + 技术文档 + WEB设计与制作 + jQuery Sequential List
上一篇:200多种网页安全用色  下一篇:没有了
jQuery Sequential List
Terminator 更新于 2009-04-02 23:47

View】 【收藏】【推荐】【评论 查看详细资料 发送留言 加为好友

Have you ever had to manually code something that is sequential? Didnt you find it annonying? Well, here is a simple solution for you. This tutorial will show you how to use jQuery to add a sequent of CSS classes to create a graphical list. The secon

Have you ever had to manually code something that is sequential? Didn’t you find it annonying? Well, here is a simple solution for you. This tutorial will show you how to use jQuery to add a sequent of CSS classes to create a graphical list. The second example will show you how to add a comment counter to a comment list using jQuery’s prepend feature.
View Demo  Sequential List  http://sincol.net/code/html/js/0902/js_list/
1a. Insert jQuery Code
First, download a copy of jQuery. In between the <head> tag, insert the jQuery code:
<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">
$(document).ready(function(){

  $("#step li").each(function (i) {
    i = i+1;
    $(this).addClass("item" i);
   });

});
</script>
The jQuery will output the source code as:
code explain
1b. CSS Code
Style the <li> element with a background image accordingly (step1.png, step2.png, step3.png, and so on..).
#step .item1 {
 
background: url(step1.png) no-repeat;
}

#step .item2 {
 
background: url(step2.png) no-repeat;
}

#step .item3 {
 
background: url(step3.png) no-repeat;
}
step list
 2a. Add Sequential Content
You can also use this technique to add sequential content using jQuery’s prepend feature. The following example shows how you can add a counter number to a comment list.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){

  $("#commentlist li").each(function (i) {
    i = i+1;
    $(this).prepend('<span class="commentnumber"> #' i '</span>');
   });

});
</script>
The code will add the <span class="commentnumber"> tag (with # + 1) to each <li> tag.
code explain

2b. CSS

Style the <li> element with position:relative and use position:absolute to place the .commentnumber to the top right corner.
#commentlist li {
 
position: relative;
}


#commentlist .commentnumber {
 
position: absolute;
 
right: 0;
 
top: 8px;
}
commentlist counter

顶一下
(4)
66.7%
踩一下
(2)
33.3%
查看所有评论
您对本文的评论
New Comment All Comment
Do not made illegal content Post your comment
My Evaluation:
My Mood:
Name Password Verification Code
投放广告
赞助商信息
上传作品
DesignShow