Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div>F12开启浏览器手机模拟器,在顶部鼠标按住移动</div>
<div class="content_father">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </div>
              
            
!

CSS

              
                    .content_father div {
      height: 200px;
      background: gray;
      margin-bottom: 10px;
    }
              
            
!

JS

              
                    let content = document.querySelector('.content_father')
    let startSite = 0 // 触摸的起始位置
    let sendAjax = false // 发送请求
    content.ontouchstart = (e) => {
      let contentSite = content.getBoundingClientRect()
      if (contentSite.y >= 0) {
        console.log('在顶部')
        startSite = e.touches[0].pageY
        // 在顶部才绑定事件
        content.ontouchmove = touchmoveFn
        content.ontouchend = touchendFn
      }
    }
    // 开始移动
    function touchmoveFn(e) {
      // 在浏览器顶部
      let moveDistance = e.touches[0].pageY - startSite // 相差高度
      const DISTANCE = 100 // 下滑距离超过100就刷新
      const DISTANCE_FONT = 50 // 下滑距离超过50 就显示文案
      if (moveDistance > DISTANCE) {
        // 下滑足够距离
        sendAjax = true
        console.log('展示 刷新页面文案')
      } else if (0 < moveDistance < DISTANCE_FONT) {
        // 下滑距离不足
        sendAjax = false // 实时更改是否发送请求
        console.log('展示:继续下滑刷新页面文案')
      } else {
        // 上拉 取消请求
        sendAjax = false // 实时更改是否发送请求
      }
      console.log('滑动距离', moveDistance)
    }
    // 触摸结束
    function touchendFn(e) {
      let contentSite = content.getBoundingClientRect()
      // 判断在顶部
      if (contentSite.y >= 0) {
        // 并且上次上滑超过100
        if (sendAjax) {
          console.log('发送 请求')
        }
      }
      // 清除事件
      content.ontouchmove = null
      content.ontouchend = null
    }
              
            
!
999px

Console