网站建设资讯

NEWS

网站建设资讯

jquery鼠标移入,jquery鼠标移入轮播图焦点是停止自动轮播

jquery鼠标移入移出

mouseenter(进入)、mouseleave、mouseover(覆盖)和mouseout是常用来判断鼠标移出和移入的事件句柄,虽然功能上差不多,但是细节却有不同的地方。

创新互联建站成立于2013年,先为武穴等服务建站,武穴等地企业,进行企业商务咨询服务。为武穴企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

mouseover和mouseout在父元素和其子元素都可以触发,当鼠标穿过一个元素时,触发次数得依子元素数量而言。

mouseenter和mouseleave只在父元素触发,当鼠标穿过一个元素时,只会触发一次。

mouseover和mouseout比mouseenter和mouseleave先触发

因此一般mouseover和mouseout一起使用,mouseenter和mouseleave一起使用

jQuery链式调用、鼠标移入移出、轮播、键盘事件

style

    *{

        margin: 0%;

        padding: 0%;

    }

    .box{

        width: 340px;

        border: 1px solid blue;

        margin: 10px auto;

    }

    .box h1{

        height: 40px;

        color: #fff;

        padding-left: 15px;

        background-color: blue;

        font-size: 25px;

    }

    ul li{

        padding-left: 15px;

        list-style-type: none;

        line-height: 45px;

        border-bottom: 1px dashed #ccc;

    }

    ul li:last-child{

        border-bottom: none;

    }

/style

/head

body

div class="box"

    h1

        祝福冬奥

    /h1

    ul

      li贝克汉姆/li

      li 姚明/li

      li张宏/li

      li肖恩怀特/li

  /ul

  /div

script src="./jquery-1.12.4.js"/script

script

    /* jQuery的链式调用 */

    /* $('div').$('div').text('我是学生').css('color','red').attr({name:'zhangsan',age:30}) */

    /* 链式调用的原理jq里面的方法都会return this 把当前调用者return出去实现链式调用 */

  /* $('ul li').first().css('background','yellow').end().eq(1).css('background','red') */

    /* 获取的只是content里面的距离,不包括padding margin border里面的距离 */

    /* 返回以像素为单位的top和left的坐标,仅对可见元素有效 */

    /* top和left值都会包括自己的margin和父元素border的值 */

    console.log($('div2').offset().top);

    console.log($('ul').width());

    console.log($('ul').height());

    /* offsetParent 返回最近的自己定位的祖先元素 */

    console.log($('div2').offsetParent());

    /* position() 返回第一个匹配元素相对于父元素的位置 */

    console.log($('div').position());

  /* scrollLeft([position]) 参数可选,设置返回匹配元素相对滚动条左侧的偏移*/

    /* 设置滚动条的距离 */

    $(window).scrollLeft(100)

    /* 获取滚动条的距离 */

    $(window).scroll(function(){

        console.log($(document).scrollLeft());

    })

/script

style

    .div1{

        width: 300px;

        height: 300px;

        border: 1px solid red;

    }

    .div2{

        width: 200px;

        height: 200px;

        background-color: red;;

    }

/style

/head

body

div class="div1"

    div class="div2"

  /div

/div

script src="./jquery-1.12.4.js"/script

script

    /* mouseenter mouseleave 在进入子元素区域时不会触发

       mouseover 和mouseout 会触发 */

    /* $('.div1').mouseenter(function(){

        $(this).css('background','green')

    })

    $('.div1').mouseleave(function(){

        $(this).css('background','yellow')

    }) */

    /* 由mouseenter 和mouseleave组成 */

    $('.div1').hover(function(){

        $(this).css('background','yellow')

        console.log(1);

    })

/script

style

    *{

        margin: 0%;

        padding: 0%;

    }

    .box{

        width: 340px;

        border: 1px solid blue;

        margin: 10px auto;

    }

    .box h1{

        height: 40px;

        color: #fff;

        padding-left: 15px;

        background-color: blue;

        font-size: 25px;

    }

    ul li{

        padding-left: 15px;

        list-style-type: none;

        line-height: 45px;

        border-bottom: 1px dashed #ccc;

    }

    ul li:last-child{

        border-bottom: none;

    }

/style

/head

body

div class="box"

    h1

        祝福冬奥

    /h1

    ul

      li贝克汉姆/li

      li 姚明/li

      li张宏/li

      li肖恩怀特/li

  /ul

  /div

  script src="./jquery-1.12.4.js"/script

  script

    /* $('li:eq(0)').mouseenter(function(){

        $(this).css('background','red')

    })

    $('li:eq(0)').mouseout(function(){

        $(this).css('background','')

    }) */

    $('li').hover(function(){

        /* css('background','')不会改变元素原来bgc样式 */

        $('li').first().css('background','red').siblings().css('background','')

    })

    $('li:eq(1)').mouseenter(function(){

        $(this).css('background','yellow')

    })

    $('li:eq(1)').mouseout(function(){

        $(this).css('background','')

    })

  /script

style

    .box{

        margin: 30px auto;

        width: 500px;

        height: 300px;

        border: 1px solid cyan;

        position: relative;

    }

    .img-list img{

        width: 500px;

        height: 300px;

        display: block;

        position: absolute;

        left: 0;

        top: 0;

    }

/style

/head

body

div class="box"

    div class="img-list"

        img src="./imgs/1.jpg" alt=""

        img src="./imgs/2.jpg" alt=""

        img src="./imgs/3.jpg" alt=""

        img src="./img/4.jpg" alt=""

    /div

/div

button style="margin-left: 450px;" class="left"后退/button

button class="right"前进/button

script src="./jquery-1.12.4.js"/script

script

    /* 定时器 过2s 显示一张图 显示最后一张图的时候再跳回第一张 */

    /* let i = 0

    $('img').eq(0).show().siblings().hide();

    setInterval(function(){

      i++;

      if(i==$('img').length){

          i=0

      } */

      /* 淡入淡出 */

      /* $('img').eq(i).fadeIn('slow').siblings().fadeOut('slow')

    },2000) */

  let i = 0;

    let timer = null

    $('img').eq(i).show().siblings().hide();

    /* 自动播放 */

    show();

    $('.left').click(function(){

        /* 先清空定时器 阻止自动播放 */

        clearInterval(timer);

        i--;

        /* 防止减到-1找不到对应的图片 */

        if(i == -1){

          i=$('img').length - 1

        }

        /* 展示当前对应的图片其他图片淡出 */

        $('img').eq(i).show().siblings().hide();

        /* 继续开始自动播放 */

        show();

    })

    $('.right').click(function(){

        /* 先清空定时器 阻止自动播放 */

        clearInterval(timer);

        i++;

        /* 防止减到-1 找不到对应的图片 */

        if(i==$('img').length){

          i=0

        }

        /* 展示当前对应的图片其他图片淡出 */

        $('img').eq(i).show().siblings().hide();

        /* 继续开始自动播放 */

        show()

        /* 定时器 过两秒 显示一张图 显示最后一张图的时候

        再跳到第一张 */

    })

    function show(){

        timer = setInterval(function (){

            i++;

            if(i == $('img').length){

               i = 0

            }

            /* fadeIn 淡入 fadeOut淡出 */

            $('img').eq(i).fadeIn().siblings().fadeOut();

        },2000)

    }

/script

body

用户名:input type="text"br

密码: input type="password"

script src="./jquery-1.12.4.js"/script

script

    /* 按下键盘 */

    /* $('input[type=text]').keydown(function(){

        alert('我按下了')

    }) */

  /* 抬起键盘 */

    /* $('input[type=password]').keyup(function(){

        alert('我抬起了')

    }) */

  /* keypress 连续敲击键盘 */

    /* $('input[type=text]').keypress(function(){

        alert('连续打字')

    }) */

    $(window).keyup(function(e){

        if(e.keyCode==13){

            alert('已提交')

        }

    })

/script

/body

前端 jQuery鼠标移入移出

mouseover() 鼠标进入(进入子元素也触发)

mouseout() 鼠标离开(离开子元素也触发)

mouseenter() 鼠标进入(进入子元素不触发)

mouseleave() 鼠标离开(离开子元素不触发)

jquery中鼠标移上和移开的动作是什么?

mouseover事件于用户把鼠标从一个元素移动到另外一个元素上时触发,mouseout事件于用户把鼠标移出一个元素时触发。\x0d\x0a下面为你详细介绍下jquery中的鼠标事件:\x0d\x0a(1):click事件:click事件于用户在元素敲击鼠标左键,并在相同元素上松开左键时触发;\x0d\x0a$('p').click(function(){\x0d\x0aalert('click function is running\x0d\x0a!');\x0d\x0a});\x0d\x0a(2):dbclick事件:dbclick事件在用户完成迅速连续的两次点击之后触发,双击的速度取决于操作系统的设置。一般双击事件在页面中不经常使用;\x0d\x0a$('p').dbclick(function(){\x0d\x0aalert('dbclick function is running\x0d\x0a!');\x0d\x0a});\x0d\x0a(3):mousedown事件:mousedown事件在用户敲击鼠标键时触发,跟keydown事件不一样,该事件仅在按下鼠标时触发;\x0d\x0a$('p').mousedown(function(){\x0d\x0aalert('mousedown function is\x0d\x0arunning !');\x0d\x0a});\x0d\x0a(4):mouseup事件:mouseup事件在用户松开鼠标时触发,如果在与按下鼠标的元素相同元素上松开,那么click事件也会触发;\x0d\x0a$('p').mouseup(function(){\x0d\x0aalert('mouseup function is running\x0d\x0a!');\x0d\x0a}).click(function(){\x0d\x0aalert('click\x0d\x0afunction is running too !');\x0d\x0a});\x0d\x0a(5):mouseover事件:mouseover事件于用户把鼠标从一个元素移动到另外一个元素上时触发,如果需要知道来自那个元素可以使用,relatedTagrget属性;\x0d\x0a(6):mouseout事件:mouseout事件于用户把鼠标移出一个元素时触发,这包括从父元素移动到子元素上,或者使用键盘跳到元素上。


文章名称:jquery鼠标移入,jquery鼠标移入轮播图焦点是停止自动轮播
文章源于:http://cdweb.net/article/dsdpppj.html