/**
 * 手机端调起摄像头拍照
 * @returns 
 */
const selfie = () => new Promise((resolve, reject) => {
    try {
        let input = document.createElement("input");
        input.setAttribute("type", "file");
        input.setAttribute("accept", "image/*");
        input.setAttribute("capture", "user");
        input.style.display = "none";
        let picture = null;
        input.addEventListener("change", () => {
            picture = input.files[0];
            document.body.removeChild(input);
            resolve(picture);
        });
        document.body.appendChild(input);
        input.click();
    } catch (error) {
        reject(error);
    }
});

文章作者: CaptainTwo
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 CaptainTwo
JavaScript JavaScript
喜欢就支持一下吧