码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • utils工具 常见函数


    1. /**
    2. * 判断是移动还是pc设备
    3. * @returns {String}
    4. */
    5. export const isMobile = () => {
    6. if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i))) {
    7. return 'mobile';
    8. }
    9. return 'desktop';
    10. }
    11. /**
    12. * 判断是苹果还是安卓设备
    13. * @returns {String}
    14. */
    15. export const isAppleMobileDevice = () => {
    16. let reg = /iphone|ipod|ipad|Macintosh/i;
    17. return reg.test(navigator.userAgent.toLowerCase());
    18. }
    19. /**
    20. * 判断是否为微信/QQ的内置浏览器
    21. * @returns {Boolean}
    22. */
    23. export const broswer = () => {
    24. const ua = navigator.userAgent.toLowerCase();
    25. if (ua.match(/MicroMessenger/i) == "micromessenger") {
    26. return "weixin";
    27. } else if (ua.match(/QQ/i) == "qq") {
    28. return "QQ";
    29. }
    30. return false;
    31. }
    32. /**
    33. * 滚动到页面顶部
    34. */
    35. export const scrollToTop = () => {
    36. const height = document.documentElement.scrollTop || document.body.scrollTop;
    37. if (height > 0) {
    38. window.requestAnimationFrame(scrollToTop);
    39. window.scrollTo(0, height - height / 8);
    40. }
    41. }
    42. /**
    43. * 滚动到页面底部
    44. */
    45. export const scrollToBottom = () => {
    46. window.scrollTo(0, document.documentElement.clientHeight);
    47. }
    48. /**
    49. * 获取可视窗口高度
    50. */
    51. export const getClientHeight = () => {
    52. let clientHeight = 0;
    53. if (document.body.clientHeight && document.documentElement.clientHeight) {
    54. clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    55. }
    56. else {
    57. clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
    58. }
    59. return clientHeight;
    60. }
    61. /**
    62. * 获取可视窗口宽度
    63. */
    64. export const getPageViewWidth = () => {
    65. return (document.compatMode == "BackCompat" ? document.body : document.documentElement).clientWidth;
    66. }

  • 相关阅读:
    【面经】摩根士丹利面经
    Node.js全栈指南:浏览器显示一个网页
    上传自己的私有的(公共的)CocoaPods支持库
    有意思网站合集2
    大型网站技术架构核心原理与案例分析学习笔记(实践篇)
    HTTP协议【网络基础/应用层】
    C:warning: null argument where non-null required (argument 2) [-Wnonnull]
    STM32中的Systick的使用
    .NET餐厅管理系统sql数据帮助类C#利用反射获取对象属性值、将sr_readStr数组存入数据库image类型的字段中
    RocketMQ系列-搭建Namesrv源码调试环境
  • 原文地址:https://blog.csdn.net/cdx1170776994/article/details/126402874
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号