jQuery基础知识

本文介绍了jQuery的基本使用技巧,包括文档加载完成触发、鼠标点击事件响应、元素样式的动态增删、渐变及滑动动画效果实现等,适用于网页交互设计。

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

1.$(document).ready
 文档加载完毕的时候发生
例如:$(document).ready(function()){alert(‘document是获取整个文档对象’);})
2.鼠标点击事件
例如:
$(document).ready(function){
$(‘div’).click(function(){
alert(‘’test);
})
})
<div id=”test1”>test1</div>
<div id=”test2”>test2</div>
3.增加样式和删除样式
$(document).ready(function){
$(‘div’).addClass(‘background-color’,’red’);
$(‘div’).click(function(){
$(this).removeClass(‘‘background-color’,’red’’);
})
})
$(this)是传过来的当前对象,不是所有对象
4.渐变效果实现
fadeout(speed,callback)渐变浅,完成后回调callback, callback可选
fadeIn(speed,callback)渐变深,完成后回调callback, callback可选
fadeTo(speed,opacity,callback)调整到opacity,opacity为0-1可选
speed(string|number),string可选为slow,normal,fast,number为毫秒数
例如:
$(document).ready(function){
$(‘#test1’).click(function(){
$(‘#test2’).fadeOut(‘slow’,function(){
Alert(‘慢慢消失’);
})
$(‘#test3’).click(function(){
$(‘#test2’).fadeIn(‘slow’,function(){
Alert(‘慢慢出现’);
})
$(‘#test4’).click(function(){
$(‘#test2’).fadeTo(‘slow’,1,function(){
Alert(‘慢慢变化’);
})
})
<div id=”test1”>test1</div>
<div id=”test2”>test2</div>
<div id=”test3”>test3</div>
<div id=”test4”>test4</div>
5.滑动效果实现
slideDown(speed,callback)动态显示,通过id.slidDown这样的用法把id向下滑动打开
slideUp(speed,callback)动态隐藏,实际上是把id.slideUpde的id向上滑动隐藏
slideToggle(speed,callback)同时具备上述两个功能
例如:
$(document).ready(function){
$(‘#test1’).click(function(){
$(‘#test2’).slideDown(‘slow’);
})
$(‘#test3’).click(function(){
$(‘#test2’).slideUp(‘slow’);
})
$(‘#test4’).click(function(){
$(‘#test2’).slideToggle(‘slow’);
})
})
站长www.software8.co/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值