<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
            padding: 0px;
            margin: 0px;
            position: relative;
            left: 100px;
            width: 300px;
            height: 300px;
            background: #ccc;

            position: absolute;
            top: 100px;
            left: 100px;
            width: 100px;
            height: 100px;
            background: blueviolet;
    <div class="wrapper">
        <div class="one">

    <script src="../jqueryFile/jquery-3.4.1.js"></script>
        console.log( $(".one").offset() );      // {top: 200, left: 200}    相对于屏幕
        console.log( $(".one").position() );    // {top: 100, left: 100}    相对于最近的有定位的父容器
        // 设置offset()、position()值
            left: 50,
            top: 50


        console.log( $(".one").offset() );      // {top: 50, left: 50}    相对于屏幕
        console.log( $(".one").position() );    // {top: -50, left: -50}    相对于最近的有定位的父容器
Last modification:July 4th, 2019 at 09:57 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment