JavaScript 函数的一些

生成随机颜色

const generateRandomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16)}`

console.log(generateRandomHexColor())

复制到剪切板

const copyToClipboard = (text) => navigator.clipboard && navigator.clipboard.writeText && navigator.clipboard.writeText(text)

copyToClipboard("Hello World!")

滚动到顶部

const scrollToTop = (element) => 
  element.scrollIntoView({ behavior: "smooth", block: "start" });

滚动到底部

const scrollToBottom = (element) => 
  element.scrollIntoView({ behavior: "smooth", block: "end" });

你可能感兴趣的:(javascript,开发语言,ecmascript)