请问老师错误在哪里

来源:1-9 编程练习

hy_wang

2018-05-09 20:34:23

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>IE6~IE8下的渐变</title>
    <style type="text/css">
        .one{
            width: 500px;
            height: 500px;
        }
        div.two{
            width: 500px;
            height: 500px;
            background: url('webwxgetmsgimg.jpg') ;
           /* background-position: -500px -500px;*/
           background-position:80% 80%;
           /*background-position: 173px 50px;*/
         /* background-position: 250px 250px;*/
           background-repeat: no-repeat;
           background-size: 500px 500px;


           
            }
        div.one{
            width: 500px;
            height: 500px;
            background-color: red;
        }
        .three{
            width: 150px;
            height: 500px;
            background-color: #000;
        }
    </style>
</head>
<body>
    <div class="one"></div>
    <div class="two"></div> 
   <!--  <div class="three"></div> -->
<script
  src="https://code.jquery.com/jquery-3.3.1.js"
  integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  crossorigin="anonymous"></script>
<script type="text/javascript">
    var one=document.getElementsByClassName('one');
    var two=document.getElementsByClassName('two');
    console.log($('.one').pageX);
</script>
</body>
</html>

请问老师这个为什么是undefined 不是应该是0嘛。。pagex不是元素和文档的定位吗

写回答

2回答

小于飞飞

2018-05-10

元素对于文档的左边距离使用$('.one').offset().left,动手实践,祝学习愉快。

0

妮可妮可妮_

2018-05-10

pageX() 属性是鼠标指针的位置,没有进行鼠标操作事件,所以为undefined

0
hy_wang
h 那请问老师我想知道div和对于文档的左边距离应该使用什么方法或者属性
h018-05-10
共1条回复

0 学习 · 5012 问题

查看课程