夜光序言:
我把星星藏在心里,把月亮揽入怀中,然后转身对你说,纸短情长,我引月送你。
正文:使用自定义效果来隐藏匹配的元素。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:.hide() 演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
div {
width: 100px;
height: 100px;
background: #ccc;
border: 1px solid #000;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<button>隐藏 div</button>
<div></div>
<script>
$( "button" ).click(function() {
$( "div" ).hide( "drop", { direction: "down" }, "slow" );
});
</script>
</body>
</html>
突出特效(Highlight Effect)通过首先改变背景颜色来隐藏或显示一个元素。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:突出特效(Highlight Effect)演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
#toggle {
width: 100px;
height: 100px;
background: #ccc;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<p>点击任意地方进行切换。</p>
<div id="toggle"></div>
<script>
$( document ).click(function() {
$( "#toggle" ).toggle( "highlight" );
});
</script>
</body>
</html>
调整元素尺寸到指定宽度和高度。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:尺寸特效(Size Effect)演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
#toggle {
width: 100px;
height: 100px;
background: #ccc;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<p>点击任意地方进行尺寸调整。</p>
<div id="toggle"></div>
<script>
$( document ).click(function() {
$( "#toggle" ).effect( "size", {
to: { width: 200, height: 60 }
}, 1000 );
});
</script>
</body>
</html>
把元素滑动出视区。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:滑动特效(Slide Effect)演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
#toggle {
width: 100px;
height: 100px;
background: #ccc;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<p>点击任意地方进行切换。</p>
<div id="toggle"></div>
<script>
$( document ).click(function() {
$( "#toggle" ).toggle( "slide" );
});
</script>
</body>
</html>
当动画样式改变时,为匹配的元素集合内的每个元素添加和移除指定的 Class。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:.switchClass() 演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
div {
width: 100px;
height: 100px;
background-color: #ccc;
}
.big {
width: 200px;
height: 200px;
}
.blue {
background-color: #00f;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<div class="big"></div>
<script>
$( "div" ).click(function() {
$( this ).switchClass( "big", "blue", 1000, "easeInOutQuad" );
});
</script>
</body>
</html>
当动画样式改变时,根据 Class 是否存在以及 switch 参数的值,为匹配的元素集合内的每个元素添加或移除一个或多个 Class。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:.toggleClass() 演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
div {
width: 100px;
height: 100px;
background-color: #ccc;
}
.big-blue {
width: 200px;
height: 200px;
background-color: #00f;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<div></div>
<script>
$( "div" ).click(function() {
$( this ).toggleClass( "big-blue", 1000, "easeOutSine" );
});
</script>
</body>
</html>
把一个元素的轮廓转移到另一个元素。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>夜光:转移特效(Transfer Effect)演示</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
div.green {
width: 100px;
height: 80px;
background: green;
border: 1px solid black;
position: relative;
}
div.red {
margin-top: 10px;
width: 50px;
height: 30px;
background: red;
border: 1px solid black;
position: relative;
}
.ui-effects-transfer {
border: 1px dotted black;
}
</style>
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<div class="green"></div>
<div class="red"></div>
<script>
$( "div" ).click(function() {
var i = 1 - $( "div" ).index( this );
$( this ).effect( "transfer", { to: $( "div" ).eq( i ) }, 1000 );
});
</script>
</body>
</html>