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

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

<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-1124js"></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的值 /

        consolelog($('div2')offset()top);

        consolelog($('ul')width());

        consolelog($('ul')height());

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

        consolelog($('div2')offsetParent());

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

        consolelog($('div')position());

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

        / 设置滚动条的距离 /

        $(window)scrollLeft(100)

        / 获取滚动条的距离 /

        $(window)scroll(function(){

            consolelog($(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-1124js"></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')

            consolelog(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-1124js"></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/1jpg" alt="">

            <img src="/imgs/2jpg" alt="">

            <img src="/imgs/3jpg" alt="">

            <img src="/img/4jpg" alt="">

        </div>

    </div>

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

    <button class="right">前进</button>

    <script src="/jquery-1124js"></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-1124js"></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(ekeyCode==13){

                alert('已提交')

            }

        })

    </script>

</body>

IE6下面一样可以PNG透明, 只是效果不是很好。

解码以后代码如下:

(function(m){jQueryfnpngFix=function(c){c=jQueryextend({blankgif:'blankgif'},c);var e=(navigatorappName=="Microsoft Internet Explorer"&&parseInt(navigatorappVersion)==4&&navigatorappVersionindexOf("MSIE 55")!=-1);var f=(navigatorappName=="Microsoft Internet Explorer"&&parseInt(navigatorappVersion)==4&&navigatorappVersionindexOf("MSIE 60")!=-1);if(jQuerybrowsermsie&&(e||f)){jQuery(this)find("img[src$=png]")each(function(){jQuery(this)attr('width',jQuery(this)width());jQuery(this)attr('height',jQuery(this)height());var a='';var b='';var g=(jQuery(this)attr('id'))'id="'+jQuery(this)attr('id')+'" ':'';var h=(jQuery(this)attr('class'))'class="'+jQuery(this)attr('class')+'" ':'';var i=(jQuery(this)attr('title'))'title="'+jQuery(this)attr('title')+'" ':'';var j=(jQuery(this)attr('alt'))'alt="'+jQuery(this)attr('alt')+'" ':'';var k=(jQuery(this)attr('align'))'float:'+jQuery(this)attr('align')+';':'';var d=(jQuery(this)parent()attr('href'))'cursor:hand;':'';if(thisstyleborder){a+='border:'+thisstyleborder+';';thisstyleborder=''}if(thisstylepadding){a+='padding:'+thisstylepadding+';';thisstylepadding=''}if(thisstylemargin){a+='margin:'+thisstylemargin+';';thisstylemargin=''}var l=(thisstylecssText);b+='<span '+g+h+i+j;b+='style="position:relative;white-space:pre-line;display:inline-block;background:transparent;'+k+d;b+='width:'+jQuery(this)width()+'px;height:'+jQuery(this)height()+'px;';b+='filter:progid:DXImageTransformMicrosoftAlphaImageLoader(src=\''+jQuery(this)attr('src')+'\', sizingMethod=\'scale\');';b+=l+'"></span>';if(a!=''){b='<span style="position:relative;display:inline-block;'+a+d+'width:'+jQuery(this)width()+'px;height:'+jQuery(this)height()+'px;">'+b+'</span>'}jQuery(this)hide();jQuery(this)after(b)});jQuery(this)find("")each(function(){var a=jQuery(this)css('background-image');if(aindexOf("png")!=-1){var b=asplit('url("')[1]split('")')[0];jQuery(this)css('background-image','none');jQuery(this)get(0)runtimeStylefilter="progid:DXImageTransformMicrosoftAlphaImageLoader(src='"+b+"',sizingMethod='scale')"}});jQuery(this)find("input[src$=png]")each(function(){var a=jQuery(this)attr('src');jQuery(this)get(0)runtimeStylefilter='progid:DXImageTransformMicrosoftAlphaImageLoader(src=\''+a+'\', sizingMethod=\'scale\');';jQuery(this)attr('src',cblankgif)})}return jQuery}})(jQuery);

$("p_Alt",PF) 含义是:PF是用某种选择器获得的一个对象(变量) ,意思是包含在PF这个div下的类名为p_Alt的标签对象

$strInit = $("p_Alt", pF)含义是:包含在PF这个div下的类名为p_Alt的标签对象赋给变量$strInit

作用是:变量$strInit代表在PF这个div下的类名为p_Alt的标签对象 代码中,“$strInit” 这个变量肯定在前面有定义:var $strInit;后面可能最少有两次以上用到此变量

以上就是关于jQuery链式调用、鼠标移入移出、轮播、键盘事件全部的内容,包括:jQuery链式调用、鼠标移入移出、轮播、键盘事件、jquery高手进、jQuery $(".p_Alt",PF) 语法含义是怎样的 $("class类",DIV )等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/web/9296670.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存