Coder Social home page Coder Social logo

albancrepel / vue-displacement-slideshow Goto Github PK

View Code? Open in Web Editor NEW
207.0 6.0 28.0 13.55 MB

A Vue.js slideshow component working with Three.js

Home Page: https://vue-displacement-slideshow.now.sh

License: MIT License

Vue 74.51% JavaScript 23.77% HTML 1.72%
threejs webgl vuejs images slideshow

vue-displacement-slideshow's Introduction

vue-displacement-slideshow

Webgl image displacement transitions made simple. A Vue.js slideshow component working with Three.js and GSAP. It works with Vue3 and older versions (until 3.0.1) work with Vue2.

Demo

Demo gif

The canvas can be interactive as well by setting the isInteractive props to true. See the props section to find more.

Live demo

DEMO

Installation

# using yarn
yarn add vue-displacement-slideshow
# or using npm
npm i vue-displacement-slideshow

โš ๏ธ If you are using this component with Vue2, you have to use this version: 3.0.1, as the ones that follow only support Vue3. You can install a particular version like this:

# using yarn
yarn add [email protected]
# or using npm
npm i [email protected]

Example

<template>
    <vue-displacement-slideshow
            :images="images"
            displacement="require('../assets/displacement.png')"
            :intensity="0.2"
            :speedIn="1.4"
            :speedOut="1.4"
            ease="expo.out"
            ref="slideshow" />
</template>

<script>
    import VueDisplacementSlideshow from "vue-displacement-slideshow";

    export default {
        components: {
            VueDisplacementSlideshow,
        },
        computed: {
            images() {
                return [
                    require("../assets/images/1.jpg"),
                    require("../assets/images/2.jpg"),
                    require("../assets/images/3.jpg")
                ];
            }
        },
        methods: {
            init() {
                //We loop through all our images by calling the 'next' method of our component every 2 seconds
                setInterval(() => {
                    this.$refs.slideshow.next();
                }, 2000);
            }
        },
        mounted() {
            this.init();
        }
    };
</script>

With Nuxt :

Just wrap the component in a client-only component like so :

<client-only>
    <vue-displacement-slideshow />
</client-only>

This component is heavily based on this library : https://github.com/robin-dela/hover-effect

Props

name type description required default value
images Array An array containing the paths of the images you wan to use true []
displacement String The path of the displacement image true
intensity Number The intensity of the displacement false 1
speedIn Number The duration of the animation for the next image, in seconds false 1
speedOut Number The duration of the animation for the previous image, in seconds false 1
ease String The GSAP easing to use false expo.inOut
preserveAspectRatio Boolean Whether the images keep their aspect ratio (act as background-size : cover (true) or contain (false) false true
isInteractive Boolean Whether the canvas is interactive on mouse move false false
interactionFactor Number The factor of the interaction false 1
interactionDuration Number The duration of the interaction false 1
startAsTransparent Boolean Whether the canvas is initially transparent and the first transition goes to the first picture false false
angle Number The angle of the transition false Math.PI / 4

Methods

Name Description Params Returns
next Transition to the second image. void
previous Transition to the first image. void
pause Pause the current transition void
play Play the current paused animation void
insertImage(path,index) Insert an image at a given index
  • path : the path of the image
  • index : the index of the inserted image, if not provided, the image will be inserted at the end of the array. It has the same behavior as the splice method (negative number allowed)
a Promise resolved when the image is loaded
insertTransparentTexture(index) Insert a transparent texture at a given index
  • index : the index of the inserted image, it has the same behavior as the insertImage index parameter
void
removeImage(index) Remove an image at a given index
  • index : the index of the image to remove (must be different from the current image index)
void
goTo(index) Transition to a given image by its index
  • index : the index of the image to transition to
void

Events emitted

Name Description
loaded Fired when the component is ready
animationEnd Fired when the transition is done.

Behavior

The first image of the array is displayed at first. When we call the next method while currently showing the last image, it will go to the first image. When we call the previous method while currently showing the first image, it will go to the last image.

The images are displayed as we would use background-size:cover in CSS.

If you set the prop startAsTransparent to true, then it adds a texture to your images array. If you want to remove it after, you can just call the removeImage method with 0 as the index parameter value.

Contributing

Contributions are welcome ! Follow the instructions in the contributing file

License

MIT

Support

If you find the component useful, you can support my open source work via my ko-fi page.

vue-displacement-slideshow's People

Contributors

albancrepel avatar stephanedemotte avatar tkjaergaard avatar yahtnif 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vue-displacement-slideshow's Issues

canvas transparency

We tried for hours to remove the black background of the canvas as we are using PNG images for the transitions. Any hint? we really tried every possible setting of transparency but with no luck

Cant position the image properly.

It seems that Width:100% and height:100% would fix it but it doesn't. on mobile, my images are looking good. but on Desktop they get cut on edges. top and left mostly.

Please help me fix it. Check out the problem on section 5 www.dinashkenazi.com

Getting require not defined errors, is it vite compatible ?

Uncaught ReferenceError: require is not defined
at Proxy.images (App.vue:21:17)
at ReactiveEffect.run (reactivity.esm-bundler.js:190:25)
at get value [as value] (reactivity.esm-bundler.js:1171:39)
at Object.get [as images] (runtime-core.esm-bundler.js:3488:30)
at Proxy._sfc_render (App.vue:3:22)
at renderComponentRoot (runtime-core.esm-bundler.js:914:44)
at ReactiveEffect.componentUpdateFn [as fn] (runtime-core.esm-bundler.js:5649:57)
at ReactiveEffect.run (reactivity.esm-bundler.js:190:25)
at instance.update (runtime-core.esm-bundler.js:5763:56)
at setupRenderEffect (runtime-core.esm-bundler.js:5777:9)

Resize not working

Since last update (0.1.5), images are not resized anymore.

Current Fix

Call this.render() after each resize.

SSR support

Would be great to add SSR support so it works with nuxt.js too

Access current image index

Hey, first of all, I'd like to thank you for this awesome plugin!

I am trying to add text description for each image in the slideshow. Is there any way to access current image index, so I could use it so as to display appropriate text? ๐Ÿ”ฅ

Dynamically control the slider

Hi,

Thanks for this great work.
I'd like to know if you plan to integrate such features:

  • pause
  • play
  • insertSlide(imageURL, index)
  • removeSlide(index)
  • init()

Thank you,

G

Can't get the component to register in nuxt.js both manually copying it or importing

I have installed the plugin via NPM. I have registered the plugin in the plugins directory as follows:

vue-displacement-slideshow.client.js

import Vue from 'vue';
import VueDisplacementSlideshow from "vue-displacement-slideshow";
console.log(VueDisplacementSlideshow); // this seems to return the component as expected but i just can't use the component anywhere on my site
Vue.use(VueDisplacementSlideshow);

I have also imported into nuxt like so:

nuxt.config.js

plugins: [
    '~/plugins/vue-displacement-slideshow.client.js',
  ],

I received the unknown custom component error when I tried to use <vue-displacement-slideshow/>

After failing, I then tried instead, to copy over the component manually, (while keeping the dependency in package.json so to keep the plugins third party dependencies installed as required (such as three.js). However, this failed as I am now getting the following errors:

 Unexpected token '!'

and on the back end:


These dependencies were not found:                                                                                                                                          friendly-errors 18:41:28
                                                                                                                                                                            friendly-errors 18:41:28
* three/src/cameras/OrthographicCamera.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/constants.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/geometries/PlaneGeometry.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/loaders/TextureLoader.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/materials/ShaderMaterial.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/math/Vector2.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/objects/Mesh.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/renderers/WebGLRenderer.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/scenes/Scene.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&
* three/src/textures/Texture.js in ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib??vue-loader-options!./components/VueDisplacementSlideshow.vue?vue&type=script&lang=js&

I have "vue-displacement-slideshow": "^3.0.1" in my package.json

Any ideas what I am doing wrong here?

GoTo(index) and autoplay enhancements

It would be great to extend the functionality:

  • method of transition to a particular slide , something like goTo(index)

  • the option of automatic slide change time(for convenience)

to anyone getting a black screen, you have to set a real height to the parent container

I couldn't get it to load at all and then I figured out the component and its canvas both had a height of 0

One way to change it was to add this:

<style>
.vue-displacement-slideshow,
.vue-displacement-slideshow canvas {
    width: 100vw !important;
    height: 100vh !important;
}
</style>

Or I needed to give a real height (ie, not 100%) to the parent container

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.