jquery slideUp()

http://api.jquery.com/click/


Re: Creating a toggle (show and hide) for hyperlink click

作者: 
 在 01-Sep-2009 06:56 AM.
  在   Using jQuery 
Hi,

I wish to use Jquery. I am a newbie. I have a hyperlink and when a user clicks that I wish to toggel ie. show or hide the text . This is what I have so far.

<a href="#" οnclick="toggle("hidden");">FAQ</a>

<div id="hidden">
Some Questions
Some Answers
</div>

<script type="text/javascript" language="javascript">
function toggle(id) {
var state = document.getElementById(id).style.display;
if (state == 'block')
{
document.getElementById(id).style.display = 'none';
}
else
{
document.getElementById(id).style.display = 'block';
}
}
</script>

Any inputs would be greatly appreciated.
  • 无状态
  • 需要更多信息
  • 已回答
  • 等待中
Have a look at this. Will do the trick for you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Tyde's test lab</title>
   
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
   
   <script type="text/javascript">
      $(function() {
         $('a#faq').click(function() {
            $('div#hidden').toggle();
            return false;
         });
      });   
   </script>
</head>
<body>
<a href="#" id="faq">F A Q</a><br />
<br />
<div id="hidden">
Some Questions
Some Answers
</div>

</body>
</html>


.slideToggle( [ duration ], [ callback ] ) Returns: jQuery

Description: Display or hide the matched elements with a sliding motion.

  • version added: 1.0.slideToggle( [ duration ], [ callback ] )

    durationA string or number determining how long the animation will run.

    callbackA function to call once the animation is complete.

The .slideToggle() method animates the height of the matched elements. This causes lower parts of the page to slide up or down, appearing to reveal or conceal the items. If the element is initially displayed, it will be hidden; if hidden, it will be shown. The display property is saved and restored as needed. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline. When the height reaches 0 after a hiding animation, the display style property is set to none to ensure that the element no longer affects the layout of the page.

Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings 'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively.

If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but this is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.

We can animate any element, such as a simple image:

<div id="clickme">
  Click here
</div>
<img id="book" src="book.png" alt="" width="100" height="123" />

We will cause .slideToggle() to be called when another element is clicked:

$('#clickme').click(function() {<br />  $('#book').slideToggle('slow', function() {<br />    // Animation complete.<br />  });<br />});<br />


posted on 2010-10-11 09:30  lexus 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lexus/archive/2010/10/11/1847613.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值