Web设计师值得收藏的10个jQuery特效(1)(2)
6. 整块可点击性效果
这个实例将会教你如何实现内容中元素可点击性效果,Best Web Gallery的侧边栏Tab就显示这样的效果。
如果你想让class="pane-list"的<ul>内的 <li> 可点击(整块),你可以向 ".pane-list li"指派一个函数,使它被点击时,函数找到 <a>元素,重定向到它的href属性值。
- $(document).ready(function(){
- $(".pane-list li").click(function(){
- window.location=$(this).find("a").attr("href"); return false;
- });
- });
view demo:http://www.webdesignerwall.com/demo/jquery/block-clickable.html
7. 可收缩面板
让我们组合一下上面的实例,创造一给可收缩的面板(像Gmai收件箱面板l)。作者还在Web Designer Wall 的评论列表Next2Friends里应用这个。
First line: 隐藏<div class="message_body">里第一个元素以后的元素
Second line: 隐藏所有第5个<li>后面的元素
Third part: 当<p class="message_head">被点击里,显示/隐藏<div class="message_body">
Fourth part: 当<a class="collpase_all_message"> 被点击时,上提所有<div class="message_body">的元素
Fifth part: 当<a class="show_all_message"> 被点击,隐藏它,并显示<a class="show_recent_only">,并下拉第5个<li>以后的元素
Sixth part: 当<a class="show_recent_only"> 被点击时,隐藏它,并显示<a class="show_all_message">,并上提第5个 <li>以后的元素
- $(document).ready(function(){
- //hide message_body after the first one
- $(".message_list .message_body:gt(0)").hide();
- //hide message li after the 5th
- $(".message_list li:gt(4)").hide();
- //toggle message_body
- $(".message_head").click(function(){
- $(this).next(".message_body").slideToggle(500)
- return false; });
- //collapse all messages $(".collpase_all_message").click(function(){
- $(".message_body").slideUp(500) return false; });
- //show all messages
- $(".show_all_message").click(function(){
- $(this).hide()
- $(".show_recent_only").show()
- $(".message_list li:gt(4)").slideDown()
- return false; });
- //show recent messages only
- $(".show_recent_only").click(function(){
- $(this).hide()
- $(".show_all_message").show()
- $(".message_list li:gt(4)").slideUp()
- return false; });
- });
view demo:http://www.webdesignerwall.com/demo/jquery/collapsible-panels.html
8. 模仿WordPress后台评论管理面板
我想你可能见过最多次这个效果是在Wordpress后台的评论管理面板。那好,让我们来用jQuery来模仿它的效果。为了实现背景颜色,你需要包含Color Animations这个插件。
First line: 向<div class="pane"> 添加 "alt" class
Second part: 当<a class="btn-delete">被点击,激活<div class="pane">的不透明度
Third part: 当<a class="btn-unapprove">被点击, 首先让<div class="pane">显示黄色,然后变为白色,并添加类(addClass)"spam"
Fourth part: 当<a class="btn-approve">被点击,首先让<div class="pane">显示绿色,然后变为白色,并移除类(removeClass)"spam"
Fifth part: 当<a class="btn-spam">被点击,激活背景色为red并使其opacity ="hide"
- //don't forget to include the Color Animations plugin//<script type="text/javascript" src="jquery.color.js"></script>
- $(document).ready(function(){
- $(".pane:even").addClass("alt");
- $(".pane .btn-delete").click(function(){
- alert("This comment will be deleted!");
- $(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
- .animate({ opacity: "hide" }, "slow")
- return false; });
- $(".pane .btn-unapprove").click(function(){
- $(this).parents(".pane").animate({ backgroundColor: "#fff568" }, "fast")
- .animate({ backgroundColor: "#ffffff" }, "slow")
- .addClass("spam")
- return false; });
- $(".pane .btn-approve").click(function(){
- $(this).parents(".pane").animate({ backgroundColor: "#dafda5" }, "fast")
- .animate({ backgroundColor: "#ffffff" }, "slow")
- .removeClass("spam")
- return false; });
- $(".pane .btn-spam").click(function(){
- $(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
- .animate({ opacity: "hide" }, "slow")
- return false; });
- });
view demo:http://www.webdesignerwall.com/demo/jquery/wordpress-comments.html
9. 轮换图片展栏
如果你有一个项目需要显示多个图片,并且你不希望链向另一个页面,那么你可以在当前面加载目标链接的JPG。
首先,添加一个<em>到H2标签。
当<p class=thumbs>内的元素被点击:
◆以可视的形式显示href属性的"largePath"路径
◆以可视的形式显示title 属性的"largeAlt"
◆代换<img id="largeImg">的scr属性内可视的"largePath"路径,并代换alt属性内可视的"largeAlt"
◆设置em内的内容(h2内) 为可视的largeAlt
- $(document).ready(function(){
- $("h2").append('<em></em>')
- $(".thumbs a").click(function(){
- var largePath = $(this).attr("href");
- var largeAlt = $(this).attr("title");
- $("#largeImg").attr({ src: largePath, alt: largeAlt });
- $("h2 em").html(" (" + largeAlt + ")"); return false; });
- });
view demo:http://www.webdesignerwall.com/demo/jquery/img-replacement.html
10. 个性化不同的链接样式
在现代化的浏览器中,个性化不同的链接是非常容易的事,比如想让.pdf文件显示特殊的样式,你只需要添加上简单的CSS规则:a[href $='.pdf'] { ... }就可以实现,但不幸的是IE6并不支持这个。如果想实现这个,你可以利用jQuery。
前三行代码必需是连续的,它只是一个<a>的href属性中的一个CSS class。第二部分将会获取所有href中没有"http://www.webdesignerwall.com" 和/或没有"#"的< a>元素,并添加"external" class和target= "_blank"。
- $(document).ready(function(){
- $("a[@href$=pdf]").addClass("pdf");
- $("a[@href$=zip]").addClass("zip");
- $("a[@href$=psd]").addClass("psd");
- $("a:not([@href*=http://www.webdesignerwall.com])").not("[href^=#]")
- .addClass("external")
- .attr({ target: "_blank" });
- });
view demo:http://www.webdesignerwall.com/demo/jquery/link-types.html











