????????????????????????????????????????????????????????元素絕對(duì)位置
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>元素絕對(duì)位置</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()是獲取相對(duì)于頁面左上角的絕對(duì)位置滩援,即使外面再包一層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>
............................................................................................................................................................
????????????????????????????????????????????????????鼠標(biāo)移入移出
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鼠標(biāo)移入移出</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(){
/*進(jìn)入子元素也觸發(fā)*/
/*$('#div1').mouseover(function() {
$(this).animate({marginTop: 50});//.stop()
});
$('#div1').mouseout(function() {
$(this).animate({marginTop: 100});//.stop()
});*/
/*進(jìn)入子元素不觸發(fā)*/
/*$('#div1').mouseenter(function() {
$(this).stop().animate({marginTop: 50});//
});
$('#div1').mouseleave(function() {
$(this).stop().animate({marginTop: 100});//
});*/
/*通過hover(mouseenter+mouseleave)實(shí)現(xiàn)簡寫*/
$('#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(){
// //一開始就獲取焦點(diǎn)玩徊,相當(dāng)于設(shè)置了autofocus自動(dòng)獲取焦點(diǎn)了(HTML5 新增表單控件屬性)
// $('#txt01').focus();
// //文本框獲取焦點(diǎn)的時(shí)候(有光標(biāo)閃爍的時(shí)候)
// $('#txt01').focus(function() {
// alert('focus');
// });
// //失去焦點(diǎn)的時(shí)候(光標(biāo)離開的時(shí)候)
// $('#txt01').blur(function() {
// alert('blur');
// });
// //輸入框內(nèi)容發(fā)生變化的時(shí)候租悄,失去焦點(diǎn)后觸發(fā),可用于注冊(cè)時(shí)驗(yàn)證用戶名是否已存在
// $('#txt01').change(function() {
// alert('change');
// });
//松開鍵盤按鍵就觸發(fā)
$('#txt01').keyup(function() {
alert('keyup');
});
})
</script>
</head>
<body>
<input type="text" id="txt01">
</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">
// //JS原生寫法
// window.onload = function(){
// }
// //jQuery寫法恩袱,等同于上面寫法
// $(window).load(function(){
// })
// //ready的寫法
// $(document).ready(function(){
// })
// //ready的簡寫
// $(function(){
// })
// 窗口改變尺寸的時(shí)候泣棋,會(huì)高頻觸發(fā)
$(window).resize(function() {
console.log('3');
});
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
............................................................................................................................................................