Take your website
To the next level
Discover our newly launched customization services and elevate your web projects to new heights.
Delegate tasks, save time, and unlock the power of professional WordPress outsourcing.

Okay
  Public Ticket #1267307
Mouse hovering effect
Closed

Comments

  • Pierre-Marie started the conversation

    Hi, where can i pick mouse hover effects? I'd like apply to my revolution slider the same effect that Vertical-slider-1 features, but can't figure out where to manage this.

  •  433
    Sergio replied

    HI,

    pls. use following code (screen 1208):

    <div class="animation-wrapper">
        <canvas id="animation-visual-canvas"></canvas>
    </div>
        
    <style>
            .animation-wrapper {
                width: 100%;
                height: 1000px;
        position: absolute;
        top: 0;
        overflow: hidden;
        z-index: 1;
            }
            .animation-wrapper canvas {
                width: 100%;
                height: 100%;
                position: absolute;
                left: 0;
                top: 0;
                opacity: 1;
        z-index: 1;
            }
        </style>
        <script type="text/javascript" src=" http://codex-themes.com/thegem/wp-content/plugins/thegem-custom-options/js/TweenLite.min.js"></script>
        <script type="text/javascript" src="http://codex-themes.com/thegem/wp-content/plugins/thegem-custom-options/js/EasePack.min.js"></script>
    <script type="text/javascript">
        (function() {
            var lastTime = 0;
            var vendors = ['ms', 'moz', 'webkit', 'o'];
            for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
                window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
                window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
            }
            if (!window.requestAnimationFrame)
                window.requestAnimationFrame = function(callback, element) {
                    var currTime = new Date().getTime();
                    var timeToCall = Math.max(0, 16 - (currTime - lastTime));
                    var id = window.setTimeout(function() { callback(currTime + timeToCall); },
                        timeToCall);
                        lastTime = currTime + timeToCall;
                    return id;
                };
                if (!window.cancelAnimationFrame)
                    window.cancelAnimationFrame = function(id) {
                        clearTimeout(id);
                    };
        }());
        (function() {
            var canvas,
                contentWidth,
                contentHeight,
                ctx,
                points = [],
                target;
            function initVisualAnimation() {
                canvas = document.getElementById("animation-visual-canvas");
                resize();
                ctx = canvas.getContext('2d');
                target = {
                    x: contentWidth / 2,
                    y: contentHeight / 2
                };
                // create points
                for (var x = 0; x < contentWidth; x = x + contentWidth / 20) {
                    for (var y = 0; y < contentHeight; y = y + contentHeight / 20) {
                        var px = x + Math.random() * contentWidth / 20;
                        var py = y + Math.random() * contentHeight / 20;
                        points.push({
                            x: px,
                            originX: px,
                            y: py,
                            originY: py
                        });
                    }
                }
                // for each point find the 5 closest points
                for (var i = 0; i < points.length; i++) {
                    var closest = [];
                    var p1 = points[i];
                    for (var j = 0; j < points.length; j++) {
                        var p2 = points[j];
                        if (p1 != p2) {
                            var placed = false;
                            for (var k = 0; k < 5; k++) {
                                if (!placed) {
                                    if (closest[k] == undefined) {
                                        closest[k] = p2;
                                        placed = true;
                                    }
                                }
                            }
                            for (var k = 0; k < 5; k++) {
                                if (!placed) {
                                    if (getDistance(p1, p2) < getDistance(p1, closest[k])) {
                                        closest[k] = p2;
                                        placed = true;
                                    }
                                }
                            }
                        }
                    }
                    p1.closest = closest;
                }
                // assign a circle to each point
                for (var i in points) {
                    points[i].circle = new Circle(points[i], 2 + Math.random() * 2, 'rgba(255, 255, 255, 0.3)');
                }
                addListeners();
                animate();
                for (var i in points) {
                    shiftPoint(points[i]);
                }
            }
            function addListeners() {
                if( !('ontouchstart' in window)) {
                    window.addEventListener('mousemove', mouseMove);
                }
                window.addEventListener('resize', resize);
            }
            function mouseMove(e) {
                var posx = posy = 0;
                var offset_top = getElementPosition(canvas).top;
                if (e.pageX || e.pageY) {
                    posx = e.pageX;
                    posy = e.pageY;
                } else if (e.clientX || e.clientY)    {
                    posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                    posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
                }
                target.x = posx;
                target.y = posy - offset_top;
            }
            function getElementPosition(elem) {
                var w = elem.offsetWidth,
                    h = elem.offsetHeight,
                    l = 0,
                    t = 0;
                while (elem) {
                    l += elem.offsetLeft;
                    t += elem.offsetTop;
                    elem = elem.offsetParent;
                }
                return {
                    left: l,
                    top: t,
                    width: w,
                    height: h
                };
            }
            function resize() {
                // parent node size
                contentWidth = canvas.parentNode.offsetWidth;
                contentHeight = canvas.parentNode.offsetHeight;
                // set canvas size equal size of parent node
                canvas.width = contentWidth;
                canvas.height = contentHeight;
            }
            function getDistance(p1, p2) {
                return Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
            }
            function Circle(pos, rad, color) {
                var _this = this;
                (function() {
                    _this.pos = pos || null;
                    _this.radius = rad || null;
                    _this.color = color || null;
                })();
                this.draw = function() {
                    if (!_this.active) return;
                    ctx.beginPath();
                    ctx.arc(_this.pos.x, _this.pos.y, _this.radius, 0, 2 * Math.PI, false);
                    ctx.fillStyle = 'rgba(255, 255, 255, ' + _this.active + ')';
                    ctx.fill();
                };
            }
            function animate() {
                ctx.clearRect(0, 0, contentWidth, contentHeight);
                for (var i in points) {
                    // detect points in range
                    if (Math.abs(getDistance(target, points[i])) < 4000) {
                        points[i].active = 0.3;
                        points[i].circle.active = 0.6;
                    } else if (Math.abs(getDistance(target, points[i])) < 20000) {
                        points[i].active = 0.1;
                        points[i].circle.active = 0.3;
                    } else if (Math.abs(getDistance(target, points[i])) < 40000) {
                        points[i].active = 0.02;
                        points[i].circle.active = 0.1;
                    } else {
                        points[i].active = 0;
                        points[i].circle.active = 0;
                    }
                    drawLines(points[i]);
                    points[i].circle.draw();
                }
                requestAnimationFrame(animate);
            }
            function drawLines(p) {
                if (!p.active) {
                    return;
                }
                for (var i in p.closest) {
                    ctx.beginPath();
                    ctx.moveTo(p.x, p.y);
                    ctx.lineTo(p.closest[i].x, p.closest[i].y);
                    ctx.strokeStyle = 'rgba(255, 255, 255, ' + p.active + ')';
                    ctx.stroke();
                }
            }
            function shiftPoint(p) {
                TweenLite.to(
                    p,
                    1 + 1 * Math.random(),
                    {
                        x: p.originX - 50 + Math.random() * 100,
                        y: p.originY - 50 + Math.random() * 100,
                        ease:Circ.easeInOut,
                        onComplete: function() {
                            shiftPoint(p);
                        }
                    }
                );
            }
            window.onload = initVisualAnimation;
        })();
    </script>
    

    If you’re happy with our theme, please rate us with 5 stars on Themeforest. It keeps us motivated!  (How to rate).

    Regards Sergio Codex.

  • Natalia replied

    Hi there,

    I'm having the same problem. I want to create the same mouse hovering effect (web) as described in the message below by Pierre-Marie. I saw your reply, but I don't understand exactly where this code should be pasted. I did see your screenshot, but I don't know where to find this raw html box besides in a VC element, but where... Should I place it somewhere on revolution slider, or somewhere on the actual page, etc. Please explain. Thank you!

  • Pierre-Marie replied

    Natalia, if you use the Vertical-slider-1  demo, then the raw HTML box should be in VC where your revolution slider is (to the top of the page if the rev slider is above the fold).

  •  433
    Sergio replied

    Hi, Natalia

    pls. create a separate issue for your problem

    If you’re happy with our theme, please rate us with 5 stars on Themeforest. It keeps us motivated!  (How to rate).

    Regards Sergio Codex.