如何准确的使用你所需效果的元素

本文介绍了一系列使用jQuery实现的网页交互效果,包括滑动、折叠面板、过渡动画等,通过这些实例可以帮助开发者更好地掌握jQuery的应用。

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


$("#header")—— 获取id为”header”的元素

$("h3")—— 获取所有标签为的元素

$("div#content .photo")—— 获取所有内类为”photo”的元素

$("ul li")—— 获取所有内的元素

$("ul li:first")—— 获取内的第一个元素


[b]1.简单的滑动版[/b]



$(document).ready(function(){

$(".btn-slide" ).click(function (){

$("#panel" ).slideToggle("slow" );

$(this ).toggleClass("active" );

});

});


[b]2、折叠效果[/b]

$(document).ready(function(){

$(".accordion h3:first").addClass("active");

$(".accordion p:not(:first)").hide();


$(".accordion h3").click(function(){

$(this).next("p").slideToggle("slow").siblings("p:visible").slideUp("slow");

$(this).toggleClass("active");

$(this).siblings("h3").removeClass("active");

});
});



$(document).ready(function(){

$(".accordion2 h3").eq(2).addClass("active");

$(".accordion2 p").eq(2).show();

$(".accordion2 h3").click(function(){

$(this).next("p").slideToggle("slow").siblings("p:visible").slideUp("slow");

$(this).toggleClass("active");

$(this).siblings("h3").removeClass("active");

});
});


[b]3、Chain-able过渡效果[/b]

$(document).ready(function(){

$(".run").click(function(){

$("#box").animate({opacity: "0.1", left: "+=400"}, 1200)

.animate({opacity: "0.4", top: "+=160", height: "20", width: "20"}, "slow")

.animate({opacity: "1", left: "0", height: "100", width: "100"}, "slow")

.animate({top: "0"}, "fast").slideUp().slideDown("slow")

return false;

});
});


[b]4、消失效果[/b]


$(document).ready(function(){

$(".pane .delete").click(function(){

$(this).parents(".pane").animate({ opacity: "hide"}, "slow");

});
});


[b]5、整个块元素点击效果[/b]


$(document).ready(function(){

$(".pane-list li").click(function(){

window.location=$(this).find("a").attr("href");

return false;

});
});


[b]6、折叠面板[/b]


$(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;
});
});


[b]7、动态悬停效果[/b]

$(document).ready(function(){
$(".menu a").hover(function() {

$(this).next("em").animate({opacity: "show", top: "-75"}, "slow");

}, function() {

$(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");

});

});



$(document).ready(function(){

$(".menu2 a").append("");

$(".menu2 a").hover(function() {

$(this).find("em").animate({opacity: "show", top: "-75"}, "slow");

var hoverText = $(this).attr("title");

$(this).find("em").text(hoverText);

}, function() {

$(this).find("em").animate({opacity: "hide", top: "-85"}, "fast");

});

});


[b]8、模仿WordPress的评论后台[/b]


$(".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;

});
});



[b]9、定义不同的链接样式[/b]


$(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" });

});


[b]10.图像替换[/b]


$(document).ready(function(){

$("h2").append('');

$(".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;

});
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值