jQuery04笔记

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style type="text/css">
			#aa {

				width: 200px;
				height: 200px;
				background-color: yellow;
			}

			p {
				text-align: center;
				background-color: deeppink;
			}
			.abc{
			transform: rotate(360deg);/* x */
				transition: all 2s;
			}
		</style>
		<script src="js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			/* 一、事件 */
			//1.1 加载DOM的两种方式(区别)

			// window.onload = function() {
			// console.info("js方式");
			// }
			// $(function() {
			// 	console.info("jQuery方式");
			// })
			//在低版本中,js比jQuery慢
			//在高(3.x)版本中,js比jQuery快



			$(function() {
				//1.2 绑定事件的两种方式 [eg.:点击、悬停事件等等]
				//--元素.on/bind()
				// $("#aa").on("click",function(){
				// 	alert("嘿嘿嘿");
				// })
				// $("#aa").bind("mouseover",function(){
				// 	alert("嘿嘿嘿");
				// })
				//--元素.事件名
				// $("#aa").click(function(){
				// 	alert("干哈");
				// })
				// $("#aa").mouseover("click",function(){
				// 	alert(123);
				// })

				//1.3 合成事件/事件切换
				//--hover()悬停控制元素[div]的显示和隐藏
				// $("#aa").hide()//隐藏
				// $("a").hover(function(){//鼠标移上事件
				// 	$("#aa").show();//显示
				// },function(){//鼠标移出事件
				// 	$("#aa").hide();//隐藏
				// })
				//--toggle()点击控制元素[div]的显示和隐藏[注意版本问题:高版本成为动画效果]

				// $("#aa").hide()//隐藏
				// $("a").toggle(function(){//鼠标移上事件
				// 	$("#aa").show();//显示
				// },function(){//鼠标移出事件
				// 	$("#aa").hide();//隐藏
				// })

				// $("#aa").toggle(1000);
				//1.4 事件的传播(事件冒泡) 小p->中div->大body
				//依次添加点击事件
				// $("p").click(function(){
				// 	console.info("p被点击了");
				// })
				// $("div").click(function(){
				// 	console.info("div被点击了");
				// 	return false;//阻止传播
				// })
				// $("body").click(function(){
				// 	console.info("body被点击了");
				// })
				//1.5 事件event的坐标[了解即可 pageX,pageY]
				// $("#aa").on("click",function(e){
				// 	console.info(e.pageX,e.pageY);
				// })
				//1.6 事件的移除
				//--按钮只能点击一次[2]
				// $("#btn").click(function() {
				// 	console.info(gergehjy);//做一系列的事情
				// 	//将点击事件移除
				// 	$("#btn").unbind("click");
				// 	//禁用按钮
				// 	$("#btn").prop("disabled",true);
				// })
				
				//--按钮点击偶数次可行 奇数次不行
				// var i=1;
				// $("#btn").click(function(){
				// 	if(i%2==0){//偶数次
				// 	console.info(4552,i);
						
				// 	}
				// 	i++;
				// })
				/* 二、动画 */
				//2.1 基本动画 [回调函数]
				// $("#aa").hide()//隐藏
				// $("#xx").click(function(){
				// 	$("#aa").show(1000);
				// 	//回调函数
				// 	alert("来了老弟");
				// })
				// $("#yy").click(function(){
				// 	$("#aa").hide(1000);
				// })
				// $("#zz").click(function(){
				// 	$("#aa").toggle(1000);
				// })
				// //2.2 滑动动画
				$("#xx").click(function(){
					$("#aa").slideDown(1000);
					
				})
				$("#yy").click(function(){
					$("#aa").slideUp(1000);
				})
				$("#zz").click(function(){
					$("#aa").slideToggle(1000);
				})
				// //2.3 淡入淡出(透明度)
				// $("#aa").hide()//隐藏
				// $("#xx").click(function(){
				// 	$("#aa").fadeIn(1000);
					
				// })
				// $("#yy").click(function(){
				// 	$("#aa").fadeOut(1000);
				// })
				// $("#zz").click(function(){
				// 	$("#aa").fadeToggle(1000);
				// })
				//2.4 自定义动画
				//--缩放
				// $("#bb").on("click", function() {
				// 	$("#aa").animate({
				// 		width: 100,
				// 		heigth: 300
				// 	}, 2000);
				// })
				//--移动[2]
			
				// $("#bb").on("click", function() {
				// 	$("#aa").animate({
				// 		left: 100,
				// 		top: 300
				// 	}, 2000);
				// })
				$("#bb").on("click", function() {
					$("#aa").animate({
						left: "+=5",
						top: "+=10"
					}, 2000);
				})
				// $("#bb").click(function(){
				// 	//给div增加点击样式
				// 	$("#aa").addClass("abc");
				// })
			})
		</script>
	</head>
	<body>
		<input type="button" name="" id="btn" value="点我试试" /><br>
		<a style="text-decoration: none;" href="">显示</a>
		<button type="button" id="xx">显示(展开)[淡出]</button>
		<button type="button" id="yy">隐藏(收缩)[淡入]</button>
		<button type="button" id="zz">显示/隐藏(展开/收缩)[淡入/淡出]</button>
		<button id="bb" type="button">变变变</button>
		<div id="aa">
			<br>
			<br>
			<p>
				这是一巴掌
			</p>
		</div>
	</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,关于 jQuery 的事件,我可以和你分享一些学习笔记。 1. 绑定事件 在 jQuery 中,我们可以通过以下方式来绑定事件: ``` $(selector).event(function(){ // 事件处理程序 }) ``` 其中,`selector` 表示要绑定事件的元素,`event` 表示要绑定的事件类型,比如 `click`、`mouseover` 等等。事件处理程序则是在事件触发时要执行的代码块。 2. 多个事件绑定 我们可以通过 `on()` 方法来同时绑定多个事件: ``` $(selector).on({ event1: function(){ // 事件处理程序1 }, event2: function(){ // 事件处理程序2 } }) ``` 这样,当 `event1` 或 `event2` 中任意一个事件触发时,对应的处理程序都会被执行。 3. 解除事件 如果需要解除某个元素的事件处理程序,可以使用 `off()` 方法: ``` $(selector).off(event); ``` 其中,`event` 表示要解除的事件类型。如果不指定事件类型,则会解除该元素上所有的事件处理程序。 4. 事件委托 在 jQuery 中,我们可以使用事件委托来提高性能。事件委托是指将事件绑定到父元素上,而不是绑定到子元素上,然后通过事件冒泡来判断是哪个子元素触发了该事件。这样,当子元素数量较多时,只需要绑定一次事件,就可以监听到所有子元素的事件。 ``` $(selector).on(event, childSelector, function(){ // 事件处理程序 }) ``` 其中,`selector` 表示父元素,`event` 表示要绑定的事件类型,`childSelector` 表示要委托的子元素的选择器,事件处理程序则是在子元素触发事件时要执行的代码块。 以上是 jQuery 中事件的一些基本操作,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不想余生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值