Skip to content

Instantly share code, notes, and snippets.

@Ding-Fan
Ding-Fan / test.js
Created June 9, 2024 15:26
make bottom opaque when scroll down
const overlay = document.querySelector(".overlay");
let lastScrollTop = 0;
// console.log("I'm in.")
// Apply initial styles
overlay.style.transition = "opacity 0.5s ease";
overlay.style.opacity = "1";
window.addEventListener("scroll", () => {
@Ding-Fan
Ding-Fan / closure.js
Created March 12, 2019 06:18
interview
// 首先来看一些 pure function
(x) => x
// 这个 function 只用了一个 x ,并且这个 x 是 bound 在这个 function 的 scope 里的
(x, y) => {
const z = 8
return x + y + z
}
// 这个 function 用到了 x , y , z 。这三个家伙都是 bound 在这个 function 的 scope 内的。
@Ding-Fan
Ding-Fan / app.md
Last active March 10, 2019 11:06
写小程序 wepy 的常用 snippet 。

app.wpy 是入口文件,很多东西例如 globalData intercept onLaunch 都需要在这里配置。

其中 config 属性对应原生的 app.json 文件,build 编译时会根据 config 属性自动生成 app.json 文件,如果需要修改 config 中的内容,请使用微信提供的相关 API。

参考 wepy 文档 小程序文档

在 app.wpy 中,在 constructor 里的 intercept 里的 config 里,通过 url 是否开头含有 http:// 或 https:// 判断是否需要对通过 wepy.request 的请求添加 apiDomain ,起到类似 axios baseURL 的作用

if (!(/^https?:\/\//.test(p.url))) {
@Ding-Fan
Ding-Fan / button.html
Last active February 25, 2019 07:53
Basic Components
<body>
<style>
.button {
width: 200px;
height: 40px;
line-height: 40px;
text-align: center;
border-radius: 10px;
background-color: yellow;
font-size: 20px;
@Ding-Fan
Ding-Fan / validations.js
Created February 25, 2019 07:43
Validations
// 手机号校验
// https://blog.csdn.net/voidmain_123/article/details/78962164 正则来源
const validationRegExp = RegExp('^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\\d{8}$');

Keybase proof

I hereby claim:

  • I am ding-fan on github.
  • I am dingfan (https://keybase.io/dingfan) on keybase.
  • I have a public key ASDLnHDbUY4ENP34QT95Zr8sABpr9905AgDpk9xsIKvaYQo

To claim this, I am signing this object:

// 作业1: 摄氏度转换为华氏度
function cToF (celsius) {
return celsius + ' 摄氏度等于 ' + (celsius * 33.8).toFixed(2) + ' 华氏度'
}
console.log(cToF(24))
// 作业2:交换两个变量的值