jQuery动画/ jQuery循环/ 元素绝对位置/ 鼠标移入移出/ input框事件

jQuery动画

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>jQuery动画</title>
	<style type="text/css">
		.box{
			width: 100px;
			height: 100px;
			background-color: gold;
		}
	</style>
	<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		$(function(){
			/*
			参数:
			1、什么属性做动画,属性设置{param1: value1, param2: value2}
			2、动画执行的时间,单位毫秒
			3、动画曲线:
				swing(默认值)开始和结束慢,中间快
				linear匀速
				可省略不写
			4、回调函数,动画完成之后要做的事情,可无限嵌套
			*/
			$('#div1').animate({
				width: 200,
				height: 200},
				1000,
				function(){
					// alert('动画完了!');
					$(this).animate(
						{marginLeft: 500},
						1000,
						function(){
							$(this).animate(
								{marginTop: 500},
								1000
							)
						}
					)
				}
			);
		})
	</script>
</head>
<body>
	<div id="div1" class="box"></div>
</body>
</html>

jQuery循环

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>jQuery循环</title>
	<style type="text/css">
		
	</style>
	<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		$(function(){
			// //给全部的li设置内容和样式
			// $('.list li').html('111');
			// $('.list li').css({background:'gold'});

			//第一个参数index是索引值
			$('.list li').each(function(index) {
				// alert(index);//弹出索引值
				
				//$(this)是每一个li
				$(this).html(index);
			});
		})
	</script>
</head>
<body>
	<ul class="list">
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
	</ul>
</body>
</html>

元素绝对位置

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>元素绝对位置</title>
	<style type="text/css">
		.con{
			width: 600px;
			height: 600px;
			margin: 50px auto 0;
		}
		.box{
			width: 100px;
			height: 100px;
			background-color: gold;
			margin-bottom: 10px;
		}
		.pos{
			margin-left: 500px;
		}
		.pop{
			width: 100px;
			height: 100px;
			background-color: red;
			position: fixed;
			left:0;
			top: 0;
			display: none;
		}
	</style>
	<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		$(function(){
			var $pos = $('.pos');
			//offset()是获取相对于页面左上角的绝对位置,即使外面再包一层con居中层,也不影响效果
			var pos = $pos.offset();
			// console.log(pos);
			// alert(pos.left + "," + pos.top);
			var w = $pos.outerWidth();
			var h = $pos.outerHeight();
			// alert(w);

			$('.pop').css({left:pos.left + w,top:pos.top});

			$pos.mouseover(function() {
				$('.pop').show();
			});
			$pos.mouseout(function() {
				$('.pop').hide();
			});
		})
	</script>
</head>
<body>
	<div class="con">
		<div class="box"></div>
		<div class="box"></div>
		<div class="box pos"></div>
		<div class="box"></div>
	</div>

	<div class="pop">提示信息!</div>
</body>
</html>

鼠标移入移出

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>鼠标移入移出</title>
	<style type="text/css">
		.box{
			width: 200px;
			height: 200px;
			background-color: gold;
			margin: 100px auto 0;
		}
		.son{
			width: 100px;
			height: 100px;
			background-color: green;
		}
	</style>
	<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		$(function(){
			/*进入子元素也触发*/
			/*$('#div1').mouseover(function() {
				$(this).animate({marginTop: 50});//.stop()
			});
			$('#div1').mouseout(function() {
				$(this).animate({marginTop: 100});//.stop()
			});*/

			/*进入子元素不触发*/
			/*$('#div1').mouseenter(function() {
				$(this).stop().animate({marginTop: 50});//
			});
			$('#div1').mouseleave(function() {
				$(this).stop().animate({marginTop: 100});//
			});*/

			/*通过hover(mouseenter+mouseleave)实现简写*/
			$('#div1').hover(function() {
				$(this).stop().animate({marginTop: 50});
			}, function() {
				$(this).stop().animate({marginTop: 100});
			});
		})
	</script>
</head>
<body>
	<div id="div1" class="box">
		<div class="son"></div>
	</div>
</body>
</html>

input框事件

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>input框事件</title>
	<style type="text/css">
		
	</style>
	<script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript">
		$(function(){
			// //一开始就获取焦点,相当于设置了autofocus自动获取焦点了(HTML5 新增表单控件属性)
			// $('#txt01').focus();

			// //文本框获取焦点的时候(有光标闪烁的时候)
			// $('#txt01').focus(function() {
			// 	alert('focus');
			// });

			// //失去焦点的时候(光标离开的时候)
			// $('#txt01').blur(function() {
			// 	alert('blur');
			// });

			// //输入框内容发生变化的时候,失去焦点后触发,可用于注册时验证用户名是否已存在
			// $('#txt01').change(function() {
			// 	alert('change');
			// });

			//松开键盘按键就触发
			$('#txt01').keyup(function() {
				alert('keyup');
			});
		})
	</script>
</head>
<body>
	<input type="text" id="txt01">
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值