jQuery 效果

1.隐藏和显示

jQuery hide()演示一个简单的 jQuery hide() 方法。

jQuery hide()另一个 hide() 演示。如何隐藏部分文本。

实例:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
});
</script>
</head>
<body>
<p id="p1">如果点击“隐藏”按钮,我就会消失。</p>
<button id="hide" type="button">隐藏</button>
<button id="show" type="button">显示</button>
</body>
</html>

2.滑动

jQuery 滑动方法

通过 jQuery,您可以在元素上创建滑动效果。

jQuery 拥有以下滑动方法:

  • slideDown()
  • slideUp()
  • slideToggle()

 

jQuery slideDown() 方法

jQuery slideDown() 方法用于向下滑动元素。

语法:$(selector).slideDown(speed,callback);

实例:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".flip").click(function(){
$(".panel").slideDown("slow");
});
});
</script>

<style type="text/css">
div.panel,p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e5eecc;
border:solid 1px #c3c3c3;
}
div.panel
{
height:120px;
display:none;
}
</style>
</head>

<body>

<div class="panel">
<p>三国杀 - 领先的游卡桌游</p>
<p>在三国杀里,你可以查看任何人物的技能。</p>
</div>

<p class="flip">请点击这里</p>

</body>
</html>

3.动画

jQuery 动画 - animate() 方法

语法:$(selector).animate({params},speed,callback);

实例:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left:'250px'});
});
});
</script>
</head>

<body>
<button>开始动画</button>
<p>默认情况下,所有 HTML 元素的位置都是静态的,并且无法移动。如需对位置进行操作,记得首先把元素的 CSS position 属性设置为 relative、fixed 或 absolute。</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

posted @ 2017-09-08 21:28  折剑公子  阅读(79)  评论(0编辑  收藏  举报