npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

h5-orientation

v1.0.5

Published

横竖屏检测, 如果移动端处于横屏状态, 出现图片蒙层提示用户使用竖屏浏览页面

Readme

h5-orientation

横竖屏检测, 如果移动端处于横屏状态, 出现图片蒙层提示用户使用竖屏浏览页面

NPM JavaScript Style Guide

Install

npm install --save h5-orientation

Usage


Orientation.propTypes = {
  /**
   * 横屏还是竖屏出现弹窗, 默认横屏  landscape: 横屏   vertical: 竖屏
   */
  orientation: oneOf(['landscape', 'vertical']),
  /**
   * 用于提示用户需要切换手机方向的图片, 优先级小于 "renderContent"
   * 默认: //xoyo.xoyocdn.com/mobile/img/icon-no-horizontal.58236282.png
   */
  promptImg: string,

  /**
   * 渲染主体内容, 开发者可以自定义如横屏时展示的具体内容
   * 当该值不存在时, 使用默认属性 "promptImg"
   */
  renderContent: func
}

用法1: 不传入任何参数, 默认横屏出现弹窗遮罩

import React, { Component } from 'react'
import Orientation from 'h5-orientation'
class Example extends Component {
   render () {
     return (
       <Orientation />
     )
   }
 }

用法2: 定制化横屏或者竖屏的弹窗提示图片

import React, { Component } from 'react'
import Orientation from 'h5-orientation'
class Example extends Component {
   render () {
     return (
       <Orientation
        orientation="vertical"
        promptImg="//s2.ax1x.com/2019/01/10/FOWfu8.png"
       />
     )
   }
 }

用法3: 定制化横屏或者竖屏的弹窗内容

import React, { Component } from 'react'
import Orientation from 'h5-orientation'
import styles from './index.less'

class Example extends Component {
    renderContent = () => {
      return (
        <div className={styles.messageBox}>
          <img
            className={styles.messageImg}
            src="//s2.ax1x.com/2019/01/10/FOWfu8.png"
          />
          <p className={styles.messageText}>请横屏浏览器页面</p>
        </div>
      );
    };

   render () {
     return (
       <Orientation
        orientation = "vertical"
        promptImg = "//s2.ax1x.com/2019/01/10/FOWfu8.png"
        renderContent = {this.renderContent}
       />
     )
   }
 }

更新日志

1.0.5 20210707

  • feat: 为了解决部分特殊浏览器(vivo x9与华为p9)在软键盘被唤醒时的横竖屏的问题; 优先使用orientationchange 事件进行判断, 如浏览器不支持该事件再使用 onResize 事件使用宽高判断, 尽量减少误判

1.0.4 20210511

  • 优化判断横竖屏判断, 将原本的 screen.width 宽高判断调整为 innerWidth 和 innerHeight

1.0.3 20200110

  • 优化代码, 使用新的判断方法, 用来判断横竖屏状态

1.0.2 20191018

  • 优化代码, 如果初始化为竖屏时, 则不渲染虚拟dom

License

MIT © x13524