Open xgqfrms opened 5 years ago
Q: 这种在 IE 下的自定义滚动条,是如何实现的?
better-scroll
https://github.com/ustbhuangyi/better-scroll
https://www.viget.com/articles/better-scroll-and-resize-event-handling/
https://scantips.com/basics09.html
https://en.wikipedia.org/wiki/Image_file_formats
import "whatwg-fetch";
const fetchImage = (url = ``) => {
let imageType = "png";
if (url.includes(".jpeg")) {
imageType = "jpeg";
}
if (url.includes(".jpg")) {
imageType = "jpg";
}
if (url.includes(".gif")) {
imageType = "gif";
}
return fetch(
url,
{
method: "GET",
mode: "no-cors",
headers: {
"Content-Type": `image/${imageType}`,
},
})
.then(res => res.blob())
.then(
(blob) => {
return blob;
}
).catch(err => console.log(`fetch image error`, err));
};
const showDOM = (url = ``) => {
let imgBox = $qs(`[data-img-box="empty-banner-image-box"]`);
let no_data = `
<p data-no-data="p">
<span data-no-data="span">暂无数据</span>
</p>
`;
try {
if (url) {
let img = document.createElement(`img`);
img.src = url;
img.setAttribute(`data-img`, `empty-banner-image`);
if (imgBox) {
imgBox.innerHTML = "";
imgBox.insertAdjacentElement(`beforeend`, img);
}
}
} catch (err) {
// no data
imgBox.innerHTML = "";
imgBox.insertAdjacentHTML(`beforeend`, no_data);
throw new Error(`fetch image error`, err);
}
// fetchImage(url)
// .then(blob => {
// let objectURL = URL.createObjectURL(blob);
// // <img src="" alt="" data-img="empty-banner-image" />
// let img = document.createElement(`img`);
// img.src = objectURL;
// img.setAttribute(`data-img`, `empty-banner-image`);
// if (imgBox) {
// imgBox.innerHTML = "";
// imgBox.insertAdjacentElement(`beforeend`, img);
// }
// })
// .catch((err) => {
// // no data
// imgBox.innerHTML = "";
// imgBox.insertAdjacentHTML(`beforeend`, no_data);
// throw new Error(`fetch image error`, err);
// });
};
const fetchImage = (url = ``) => {
let imageType = "png";
if (url.includes(".jpeg")) {
imageType = "jpeg";
}
if (url.includes(".jpg")) {
imageType = "jpg";
}
if (url.includes(".gif")) {
imageType = "gif";
}
return fetch(
url,
{
method: "GET",
mode: "no-cors",
headers: {
"Content-Type": `image/${imageType}`,
},
})
.then(res => res.blob())
.then(
(blob) => {
return blob;
}
).catch(err => console.log(`fetch image error`, err));
};
CORS & blob bug
大家好,如需要办理且符合居住证积分及居转户条件的同学请到xxx处登记,截止时间本周五下班之前。
https://jzzjf.12333sh.gov.cn/jzzjf/pingfen/index.jsp
单位账号以单位组织机构代码或统一社会信用代码为准,个人账号以身份证号码为准
https://jzzjf.12333sh.gov.cn/jzzjf/index2.jsp#view2
https://github.com/js-cookie/js-cookie
Unix time was started at the beginning of 1970, that means that -1 is in 1969. And that is a commonly used value for "unknown" if the expected value is usually positive. And for cookies MaxAge a negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits.
https://stackoverflow.com/questions/21226438/javascript-date-object-returning-december-31st-1969
https://swagger.io/docs/specification/describing-request-body/
https://app.swaggerhub.com/apis/xgqfrms/test/1.0.0#/
// fetch(url, {
// method: "GET",
// mode: "cors",
// // cache: "no-cache",
// // credentials: "same-origin",
// headers: {
// "Content-Type": "application/json; charset=utf-8",
// // "Content-Type": "application/x-www-form-urlencoded",
// },
// redirect: "follow",
// referrer: "no-referrer",
// body: JSON.stringify(data), // body data type must match "Content-Type" header
// })
// .then(response => response.json()) // parses response to JSON
// .catch(error => console.error(`Fetch Error =\n`, error));
// };
const url = `https://petstore.swagger.io/v2/pet/1`;
fetch(
url,
{
method: "GET",
mode: "no-cors",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
// "Content-Type": "application/json; charset=utf-8",
},
})
.then(res => res.json())
.then(
(json) => {
console.log(`json =`, json);
}
).catch(err => console.log(`fetch json error`, err));
/*
// OK
const url = `https://petstore.swagger.io/v2/pet/1`;
fetch(
url,
{
method: "GET",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
})
.then(res => res.json())
.then(
(json) => {
console.log(`json =`, json);
}
).catch(err => console.log(`fetch json error`, err));
fetch(
url,
{
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
.then(res => res.json())
.then(
(json) => {
console.log(`json =`, json);
}
).catch(err => console.log(`fetch json error`, err));
const url = `https://petstore.swagger.io/v2/user/login?username=abc&password=123`;
fetch(
url,
{
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
.then(res => res.text())
.then(
(json) => {
console.log(`json =`, json);
}
).catch(err => console.log(`fetch json error`, err));
*/
"Content-Type": "application/x-www-form-urlencoded",
let url = `https://petstore.swagger.io/v2/user/login?{"username":"abc","password":"123"}`;
fetch(
url,
{
method: "GET",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
.then(res => res.text())
.then(
(text) => {
console.log(`text =`, text);
}
).catch(err => console.log(`fetch text error`, err));
HTML5 Canvas
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial
https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Using_images
https://codepen.io/pen/define
https://www.html5canvastutorials.com/tutorials/html5-canvas-images/ https://www.html5canvastutorials.com/advanced/html5-canvas-save-drawing-as-an-image/
https://www.w3schools.com/tags/canvas_drawimage.asp https://www.w3schools.com/graphics/canvas_images.asp
Canvas & Ruler
https://stackoverflow.com/questions/20434728/how-to-create-a-ruler-a-tool-for-canvas
https://mrfrankel.github.io/ruler/ https://github.com/mrfrankel/ruler/
https://github.com/MrFrankel/ruler/issues/12
https://codepen.io/webgeeker/pen/KBLaVp
https://codepen.io/webgeeker/full/pZmRYe/
PS: re-render
https://cdn.xgqfrms.xyz/canvas/ruler/ruler.min.css https://cdn.xgqfrms.xyz/canvas/ruler/ruler.min.js