鼠标移出移入、 focus获取焦点和blur失去焦点的运用

鼠标移出移入、 focus获取焦点和blur失去焦点的运用,第1张

<head>
<meta charset="UTF-8">

<title>无缝滚动</title>

<style type="text/css">

body,ul,li{margin:0;padding:0}

ul{list-style:none;}

slide{

width:500px;

height:100px;

border:1px solid #ddd;

margin:20px auto 0;

position:relative;

overflow:hidden;

}

slide ul{

position:absolute;/相对于slide进行绝对定位/

width:1000px;/比slide宽度大一倍,做这种连续滚动效果的时候,要在后面把内容复制一份/

height:100px;

left:0;/可以改变该值让其动起来/

top:0;

}

slide ul li{

width:90px;

height:90px;

margin:5px;

background-color:#ccc;

line-height:90px;

text-align: center;

font-size:30px;

float:left;

}

btns{

width:500px;

height:50px;

margin:10px auto 0;

}

</style>

<script type="text/javascript" src="/js/jquery-1124minjs"></script>

<script type="text/javascript">

$(function(){

var $ul = $('#slide ul');

var left = 0;

var deraction = 2;//每次滚动的距离

//内容为两套li

$ulhtml($ulhtml() + $ulhtml());

//反复循环定时器,30ms动一下可以看起来比较平滑

var timer = setInterval(move, 30);

function move(){

left -= deraction;

//当第2套li完全显示出来的时候,整个移回原点重新移动,实现向左连续滚动

if(left < -500){

left = 0;

}

//瞬间跳回,实现向右连续滚动

if(left > 0){

left = -500;

}

$ulcss({left: left});

}

$('#btn1')click(function() {

deraction = 2;

});

$('#btn2')click(function() {

deraction = -2;

});

$('#slide')mouseover(function() {

clearInterval(timer);

});

$('#slide')mouseout(function() {

timer = setInterval(move,30);

});

})

</script>

</head>

<body>

<div class="btns">

<input type="button" name="" value="向左" id="btn1">

<input type="button" name="" value="向右" id="btn2">

</div>

<div class="slide" id="slide">

<ul>

<li>1</li>

<li>2</li>

<li>3</li>

<li>4</li>

<li>5</li>

</ul>

</div>

</body>

鼠标移入要做的事情mouseover
鼠标移出要做的事情mouseout

<head>
    <meta charset="UTF-8">

    <title>鼠标移入移出</title>

    <style type="text/css">

        box{

            width: 200px;

            height: 200px;

            background-color: gold;

            margin: 100px auto 0;

        }

        son{

                width: 100px;

                height: 100px;

                background-color: green;

        }

    </style>

    <script type="text/javascript" src="js/jquery-1124minjs"></script>

    <script type="text/javascript">

         $(function(){

        /进入子元素也触发/

        /$('#div1')mouseover(function() {

        $(this)animate({marginTop: 50});//stop()

        });

        $('#div1')mouseout(function() {

        $(this)animate({marginTop: 100});//stop()

    });/

        /进入子元素不触发/

        /$('#div1')mouseenter(function() {

        $(this)stop()animate({marginTop: 50});//

        });

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

        $(this)stop()animate({marginTop: 100});//

        });/

        /通过hover(mouseenter+mouseleave)实现简写/

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

        $(this)stop()animate({marginTop: 50});

        }, function() {

        $(this)stop()animate({marginTop: 100});

            });

        })

    </script>

</head>

<body>

        <div id="div1" class="box">

                <div class="son"></div>

        </div>

</body>

创建一个子元素 促使鼠标移入到子元素才能移动

是由于时间mouse影响

则要使用mouseenter和mouseleave进行改变

也可以运用hover简化

autofocus

表单元素的值发生变化

<head>

                <meta charset="UTF-8">

                <title>input框事件</title>

                <style type="text/css">

                </style>

                <script type="text/javascript" src="js/jquery-1124minjs"></script>

                <script type="text/javascript">

                     $(function(){

                    // //一开始就获取焦点,相当于设置了autofocus自动获取焦点了(HTML5 新增表单控件属性)

                    // $('#txt01')focus();

                    // //文本框获取焦点的时候(有光标闪烁的时候)

                    // $('#txt01')focus(function() {

                    // alert('focus');

                    // });

                    // //失去焦点的时候(光标离开的时候)

                    // $('#txt01')blur(function() {

                    // alert('blur');

                    // });

                    // //输入框内容发生变化的时候,失去焦点后触发,可用于注册时验证用户名是否已存在

                    // $('#txt01')change(function() {

                    // alert('change');

                    // });

                    //松开键盘按键就触发

                    $('#txt01')keyup(function() {

                    alert('keyup');

                    });

                })

                </script>

</head>

<body>

        <input type="text" id="txt01">

</body>
<head>

            <meta charset="UTF-8">

            <title>jQuery其他事件</title>

            <style type="text/css">

            </style>

            <script type="text/javascript" src="js/jquery-1124minjs"></script>

            <script type="text/javascript">

            // // JS原生写法

            // windowonload = function(){

            // }

            // / /jQuery写法,等同于上面写法

            // $(window)load(function(){

            // })

            // //ready的写法

            // $(document)ready(function(){

            // })

            // //ready的简写

            // $(function(){

            // })

            // 窗口改变尺寸的时候,会高频触发

            $(window)resize(function() {

            consolelog('3');

            });

            </script>

</head>

<body>

            <div id="div1"></div>

</body>
鼠标移入要做的事情mouseover

鼠标移出要做的事情mouseout

解决方案如下:

<script type="text/javascript">function moveCaretToEnd(el) {    if (typeof elselectionStart == "number") {

elselectionStart = elselectionEnd = elvaluelength;

} else if (typeof elcreateTextRange != "undefined") {

elfocus();        var range = elcreateTextRange();

rangecollapse(false);

rangeselect();

}

}var textarea = documentgetElementById("test");

textareaonfocus = function() {

moveCaretToEnd(textarea);    // Work around Chrome's little problem

windowsetTimeout(function() {

moveCaretToEnd(textarea);

}, 1);

};</script>
<textarea id="test">Something</textarea>

textarea,计算机语言,指的是标签定义多行的文本输入控件。

<textarea> 标签定义多行的文本输入控件。

文本区中可容纳无限数量的文本,其中的文本的默认字体是等宽字体(通常是 Courier)。

可以通过 cols 和 rows 属性来规定 textarea 的尺寸,不过更好的办法是使用 CSS 的 height 和 width 属性。

在文本输入区内的文本行间,用 "%OD%OA" (回车/换行)进行分隔;通过 <textarea> 标签的 wrap 属性设置文本输入区内的换行模式。

textarea 标签是成对出现的,以<textarea>开始,以</textarea>结束

定义一个文本区域 (text-area) (一个多行的文本输入区域)。用户可在此文本区域中写文本。在一个文本区中,您可输入无限数量的文本。文本区中的默认字体是等宽字体 (fixed pitch)。

<!DOCTYPE HTML>
<html>
<meta charset="UTF-8" />
<head>
<title></title>
</head>
<style type="text/css">
html,
body {
margin: 0;
padding: 0;
}

demo {}
</style>
<body>
<div class="demo">
<input type="text" name="" id="" value="" style="outline: none;"/>
</div>
</body>
</html>

文本框得到焦点去边框html    文件代码清单如下:

<!doctype html>
<html lang="zh">
    <head>
     <meta charset="utf-8">
     <title>文本框得到焦点去边框</title>
     <link rel="stylesheet" href="inputOnblurcss">
    </head>
    <body>
     <input type="text" id="input1">
    <script src="inputOnblurjs"></script>
    </body>
</html>

inputOnblurjs   文件代码清单如下:

var inputO = documentgetElementById("input1");
inputOonblur = function()
  {
    inputOstyleborder = 0;
  }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13412759.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-31
下一篇 2023-07-31

发表评论

登录后才能评论

评论列表(0条)

保存