推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
he2020

JavaScript 实现滚动到页面指定位置,这行代码表达了什么?

  •  
  •   he2020 · Jan 4, 2022 · 2238 views
    This topic created in 1614 days ago, the information mentioned may be changed or developed.

    原文用 JavaScript 实现了滚动到页面指定位置的功能。
    以下这行代码什么意思?

    destinationOffsetToScroll 似乎是要滚动的距离,但看不出 documentHeight - destinationOffset < windowHeight 这个条件表达了什么。
    
    const destinationOffsetToScroll = Math.round(documentHeight - destinationOffset < windowHeight ? documentHeight - windowHeight : destinationOffset);
    

    原文在: https://pawelgrzybek.com/page-scroll-in-vanilla-javascript/

    xiao109
        1
    xiao109  
       Jan 5, 2022
    三元表达式嘛。如果 documentHeight - destinationOffset 小于 windowHeight 就返回 documentHeight - windowHeight ,否则返回 destinationOffset 。
    he2020
        2
    he2020  
    OP
       Jan 5, 2022
    @xiao109 知道是三元表达式啊,问题是 documentHeight - destinationOffset < windowHeight 这个判断是什么意思?
    iidear2015
        3
    iidear2015  
       Jan 5, 2022
    要滚到的位置是否在视窗内吧
    he2020
        4
    he2020  
    OP
       Jan 5, 2022
    @iidear2015 要判断这个做什么
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   889 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 22:34 · PVG 06:34 · LAX 15:34 · JFK 18:34
    ♥ Do have faith in what you're doing.