GithubHelp home page GithubHelp logo

vue-edge-check's Introduction

vue-edge-check

English / 中文

Check Browser Edge Reactively.To prevent transition effect triggered oddly when swipe edge with vue-router

Before

Odd Effect

After

Good Effect

Why & How ?

You can swipe with edge gesture in iOS Safari/WKWebview/Wechat. The page will trigger history.back()/history.forward() after the page is sliding finished. then the transition animation of router will still triggering, that's redundant.

So we can check if we touch the edge when move back/forward, then block current transition effect ✨

Page

Install

npm install vue-edge-check

OR

yarn add vue-edge-check

Useage

Two Propery $isEdgeLeft$isEdgeRight, Means touching left edge or right edge of page

can be used to define class in components

import and use

import EdgeCheck from 'vue-edge-check'
Vue.use(EdgeCheck)

define class

<template>
  <transition name="slide">
    <div class="test" :class="{'is-edge-back':$isEdgeLeft,'is-edge-forward':$isEdgeRight}">
      <h1>
          TEST
      </h1>
    </div>
  </transition>
</template>

define / block transition effect

// ORIGIN: set slide transition effect time
.slide-enter-active, .slide-leave-active {
  transition: all 0.3s;
}

// ORIGIN: add slide transition effect
.slide-enter,
.slide-leave-to
{
  transform: translate3d(100%, 0, 0);
}

// EXTRA: this component should have no transition with edge forward/back
.is-edge-forward.slide-enter-active,
.is-edge-back.slide-leave-active
{
  transition: all 0s;
}

// EXTRA: this component should not display at slide-leave start
// or else it will blink
.is-edge-back.slide-leave,
{
  transform: translate3d(100%, 0, 0);
}

// EXTRA: this component should display and not move at slide-enter start
// or else it will jump
.is-edge-forward.slide-enter,
{
  transform: translate3d(0, 0, 0);
}

Options

edge_width: default: 48

the width of edge check

edge_duration: default: 500

the $isEdgeLeft/$isEdgeRight property lasting time, need a bit more than transition effect time

// in case if you have a longer transition effect
Vue.use(EdgeCheck, {edge_duration:1000})

vue-edge-check's People

Contributors

gu-fan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-edge-check's Issues

在vue2.5,iphone7plus的微信公共号中使用会出现闪烁

// 修复IOS滑动效果
import EdgeCheck from 'vue-edge-check'
Vue.use(EdgeCheck, {edge_duration: 1000})

我在App.vue 中使用

<template>
  <div id="app">
    <transition name="slide">
      <!-- <navigation> -->
      <!--<keep-alive>-->
      <div :class="{'is-edge-back':$isEdgeLeft,'is-edge-forward':$isEdgeRight}">
        <router-view></router-view>
      </div>
      <!--</keep-alive>-->
      <!-- </navigation> -->
    </transition>
    <loading v-model="isLoading"></loading>
    <share-dialog v-show="showShare"></share-dialog>
  </div>
</template>

<script>
  import {Loading} from 'vux'
  import {mapGetters} from 'vuex'

  export default {
    name: 'App',
    components: {
      Loading
    },
    computed: {
      ...mapGetters({
        showShare: 'showShare',
        isLoading: 'isLoading'
      })
    }
  }
</script>

<style lang="scss">
  // ORIGIN: set slide transition effect time
  .slide-enter-active, .slide-leave-active {
    transition: all 0.3s;
  }

  // ORIGIN: add slide transition effect
  .slide-enter,
  .slide-leave-to {
    transform: translate3d(100%, 0, 0);
  }

  // EXTRA: this component should have no transition with edge forward/back
  .is-edge-forward.slide-enter-active,
  .is-edge-back.slide-leave-active {
    transition: all 0s;
  }

  // EXTRA: this component should not display at slide-leave start
  // or else it will blink
  .is-edge-back.slide-leave {
    transform: translate3d(100%, 0, 0);
  }

  // EXTRA: this component should display and not move at slide-enter start
  // or else it will jump
  .is-edge-forward.slide-enter {
    transform: translate3d(0, 0, 0);
  }
</style>

How can I use this with Nuxt.js?

Thanks for the plugin. Can I use this with Nuxt.js?

I've added this to my /plugins folder?

// vue-edge-check.js
import Vue from 'vue'
import EdgeCheck from 'vue-edge-check'
Vue.use(EdgeCheck)

And this in my nuxt.config.js:

plugins: [
    ...
    { src: '@/plugins/vue-edge-check.js', ssr: false }
  ],

However It's still not taking effect and Vue is complaining about:

Property or method "$isEdgeRight" is not defined on the instance but referenced during render.

When I use it on my component like this:

<div class="flex flex-col ..." :class="{'is-edge-back':$isEdgeLeft,'is-edge-forward':$isEdgeRight}">

What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.