Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                h1 This Pen is use to Explain the Concept of Coordinate System
hr 
h3 重要的座標
ul
    li #[span.code offset]: 指游標到"容器"左上角的偏移量,實做上各瀏覽器有些不同(Safari 以邊框外左上為原點;Chrome 和 FireFox 以邊框內左上為起點)。
    li #[span.code client]:指游標到 browser window 左上角的偏移量(不管 HTML document),滾動瀏覽器捲軸時,同樣位置座標相同。又稱 visual viewport。
    li #[span.code page]:指游標到 document 左上角的偏移量,滾動瀏覽器捲軸時,同樣位置座標不同,又稱作 layout viewport。
hr
h3 示意圖
    h5.title-border offset
    p 容器左上角為原點(0, 0),各瀏覽器實做不同。
    img(src="https://2.bp.blogspot.com/-GZ6hgeEfLUo/WR2gAOZlY5I/AAAAAAAAzB8/Cz68_1jZsfEcynfxm0T4DLkKx0rDkVEDgCLcB/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7%2B2017-05-18%2B%25E4%25B8%258B%25E5%258D%25889.21.05.png")
    h5.title-border client
    p 瀏覽器(browser)左上角為原點(0, 0)。
    img(src="https://4.bp.blogspot.com/-zqDFD6aHIoI/WR2gAAi5b2I/AAAAAAAAzCA/_SYztUIagdoko3H7crMa_OJpN8ECkhYAwCLcB/s1600/%25E8%259E%25A2%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7%2B2017-05-18%2B%25E4%25B8%258B%25E5%258D%25889.21.13.png")
    h5.title-border page
    p HTML Docuemnt 左上角為原點(0, 0)。
    img(src="https://3.bp.blogspot.com/-28FjDGNU-MQ/WR2gAMhsQ3I/AAAAAAAAzCE/HiS8fhKIAEEba4nyyikzuDR1ttXjVh7lACLcB/s1600/page.png")

.container
    p.getBoxClient Box info
.info Please Move Your Mouse
              
            
!

CSS

              
                body{
    padding: 50px;
    cursor: cell;
}

h1 {
    font-weight: bold;
    text-align: cross-hair;
}

.container {
    box-sizing: border-box;
    position: relative;
    // top: 900px;
    width: 350px;
    height: 350px;
    border: 15px solid;
    padding: 30px;
}

.info {
    position: fixed;
    padding: 10px 5px;
    top: 30px;
    left: 30px;
    border: 1px solid;
    background-color: hsla(160, 100%, 100%, 1);
}
.getBoxClient{
    white-space: pre;
}
              
            
!

JS

              
                const infoElement = document.querySelector('.info')
const getBoxClientElement = document.querySelector('.container')
const refreshBoxInfo = function() {
    console.log('scroll')
    const boxClient = getBoxClientElement.getBoundingClientRect()
    let boxInfo = ""
    for (let prop in boxClient) {
        boxInfo += prop + ": " + parseInt(boxClient[prop]) + "<br>"
    }

    getBoxClientElement.innerHTML = boxInfo + 'offsetLeft: ' + getBoxClientElement.offsetLeft
}

window.document.addEventListener('mousemove', function(e) {
    infoElement.textContent =
        `
    clientXY: (${e.clientX}, ${e.clientY}),
    pageXY: (${e.pageX}, ${e.pageY}),
    offsetXY: (${e.offsetX}, ${e.offsetY})   
    `
})

document.addEventListener('scroll', refreshBoxInfo)
              
            
!
999px

Console