11.23课堂笔记-jQuery 事件和动画

事件绑定

重点内容
1.bing()方法
结构:bind(事件类型,回调函数);

$('input[type=button]').bind('click',function(){
            lg('hello world');
        });

2.on()方法
on()方法结构和使用与bind()没有任何区别。

新版本的jQuery里面都是使用on()方法,bind()方法已经不再使用了。

<input type="button" value="点我">

$('input[type=button]').bind('click',function(){
            lg('hello world');
        });

3.阻止冒泡
使用事件对象 event 的方法stopPropagation();

$('input[type=button],div,body,html').on('click',function(event){
            lg('click');
            event.stopPropagation();
        });

4.绑定多个事件
on()方法中可以使用类似JSON结构进行处理。

$('input[type=button]').on({
            hover:function(){
                $(this).css('color','red');
            },
            mouseout:function(){
                $(this).css('color','#fff');
            },
            click:function(){
                alert('aaa');
            }
        });

5.事件解绑
使用unbind()方法解绑事件

    $('input[type=button]').on('click',function(){
            lg('click');
            $(this).unbind('click');
        });

jQuery动画
1. show() 方法和 hide() 方法
调用hide()方法会将元素的display样式改为’ none ‘。
show()方法将元素的display样式设置为先前的显示状态。
show()方法和hide()方法的参数可以指定毫秒值,缓慢的隐藏和展示。

        $('p').toggle(function(){
            $(this).hide(2000);
        },function(){
            $(this).show(2000);
        }) 

2.fadeIn()和fadeOut()方法
fadeIn()和fadeOut()方法只改变元素的不透明度。

fadeOut()方法会在指定的一段时间内降低元素的不透明度,直到元素完全消失(display:none)。

        $('p').toggle(function(){
            $(this).fadeOut();
        },function(){
            $(this).fadeIn();
        }) 

3.slideUp()方法和slideDown()方法
slideUp()方法和slideDown()方法只会改变元素的高度。

如果一个元素的 display 属性值为’none’,调用slideDown()方法时,这个元素将由上至下延伸显示。slideUp()方法正好相反,元素将由下到上缩短隐藏。

        $('p').toggle(function(){
            $(this).slideUp();
        },function(){
            $(this).slideDown();
        }) 

jQuery中任何动画效果,都可以指定3种速度参数。slow,normal和fast,使用时记得加上引号。
4.animate()方法
可以使用animate()方法来自定义动画。
结构:animate(params,speed,callback)


        $('#panel').click(function(){
            lg('click');
            $(this).animate({left:'+=500px'}, 3000);
        });

        //多重动画
        $('#panel').click(function(){
            lg('click');
            $(this).animate({left:'+=500px',top:'+=500px'}, 30000);
        });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值