美文网首页
笔试题整理(十二)

笔试题整理(十二)

作者: 迷人的洋葱葱 | 来源:发表于2017-10-10 20:56 被阅读0次

    饿了么

    一、使按钮减速滑动到页面顶部。已知页面结构如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
            p{
                height:50px;
                width:50px;
                background:black;
                position:fixed;
                right:20px;
                bottom:20px;
            }
            div{
                height:2000px;
            }
    </style>
    
    <script>
     
    </script>
    </head>
    <body>
    <p></p>
    <div></div>
    </body>
    </html>
    

    参考解法:

       window.onload=function(){
    
            var oP=document.getElementsByTagName("p")[0];
            var x=oP.offsetTop;
            oP.style.transition="transform 2s ease-out";
            oP.style.transform="translate(0px,"+"-"+x+"px)";
    
        };
    

    分析:
    1、p标签采用position:fixed定位。因此p标签需要移动的距离是其offsetTop(仅数值,没有单位px)值。
    2、因为"减速滑动",所以采用easeout。

    二、求以下两行代码的输出结果。

    alert('string' instanceof String);
    alert(new String('string') instanceof String);
    

    答案:
    false
    true
    分析:‘string’只是以string为数据类型的值,并不是String()的实例对象,因此输出false。
    new Sting('string')则是String()的实例对象,因此输出true。

    三、

    相关文章

      网友评论

          本文标题:笔试题整理(十二)

          本文链接:https://www.haomeiwen.com/subject/rqgvyxtx.html