亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何創建html滾動條?

如何創建html滾動條?

莫回無 2023-06-27 18:18:52
這個想法是創建一個 html 滾動條來實時接收日志。我正在使用FLASK,它對于創建網頁非常有用,但到目前為止只知道處理該工具的網頁的基礎知識。
查看完整描述

2 回答

?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

  1. 獲取一些文字

  2. 將其填充到元素中

  3. 將元素滾動到底部

// don't need this. It's to get the posts from the fake API

let id = 0;


// get a reference to the logs element

const logs = document.getElementById("logs");


// this takes some text, wraps in in a <pre> tag and returns the element

function makeLogEntry(str) {

  const el = document.createElement("pre");

  el.innerText = str;

  return el;

}


// This is just to tick up the post id and roll it back to 1 if we go over 100, since the fake api only has 100 posts

function getId() {

  return ++id > 100 ? 1 : id;

}


function getPost(id) {

  fetch(`https://jsonplaceholder.typicode.com/posts/${id}`)

    .then(response => response.json())

    .then(json => {

      // wrap the log message in a tag and append it to the logs

      logs.append(makeLogEntry(json.title));

      

      // scroll the logs element to the bottom

      // see (https://stackoverflow.com/questions/270612/scroll-to-bottom-of-div)

      logs.scrollTop = logs.scrollHeight;

    })

}


// fetch stuff every 2 seconds

setInterval(() => getPost(getId()), 2000);

#logs {

  width: 100%;

  height: 100px;

  border: 1px solid #ddd;

  overflow: scroll;

}

<div id="logs"></div>


查看完整回答
反對 回復 2023-06-27
?
肥皂起泡泡

TA貢獻1829條經驗 獲得超6個贊

fetch?您必須使用 javascript ,

您的服務器應該提供數據。然后你使用 JS DOM 將數據放入你想要放置的容器中。然后,要啟用滾動,您必須編寫一個包含區域大小和規則的 css overflow-y:scroll文件。

查看完整回答
反對 回復 2023-06-27
  • 2 回答
  • 0 關注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號