Skip to content

Instantly share code, notes, and snippets.

@VasiliuKr
Last active October 20, 2016 06:52
Show Gist options
  • Select an option

  • Save VasiliuKr/eec5b1e23c6e06ad4e022595428d3fce to your computer and use it in GitHub Desktop.

Select an option

Save VasiliuKr/eec5b1e23c6e06ad4e022595428d3fce to your computer and use it in GitHub Desktop.

Revisions

  1. VasiliuKr revised this gist Oct 20, 2016. 1 changed file with 2 additions and 23 deletions.
    25 changes: 2 additions & 23 deletions module.js
    Original file line number Diff line number Diff line change
    @@ -1,40 +1,19 @@
    var myMouseParallax = (function () {

    var layer = $('.parallax').find('.parallax__layer');
    var myModule = (function () {

    var init = function () {
    _setUpListeners();

    // то, что должно произойти сразу
    };

    var _setUpListeners = function () {
    $(window).on('mousemove', _moveLayers);
    // прослушка событий...
    };

    var _moveLayers = function (e) {
    var mouse_dx = e.pageX,
    mouse_dy = e.pageY,
    w = (window.innerWidth / 2) - mouse_dx,
    h = (window.innerHeight / 2) - mouse_dy;

    layer.map(function (key, value) {
    var bottomPosition = ((window.innerHeight / 2) * ((key + 1) / 100)),
    widthPosition = w * ((key + 1) / 100),
    heightPosition = h * ((key + 1) / 100);

    $(value).css({
    'bottom': '-' + bottomPosition + 'px',
    'transform': 'translate3d(' + widthPosition + 'px, ' + heightPosition + 'px, 0px)'
    });
    });
    };

    return {
    init: init
    };

    })();

    myMouseParallax.init();
    myModule.init();
  2. VasiliuKr revised this gist Oct 18, 2016. 1 changed file with 24 additions and 2 deletions.
    26 changes: 24 additions & 2 deletions module.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,40 @@
    var myModule = (function () {
    var myMouseParallax = (function () {

    var layer = $('.parallax').find('.parallax__layer');

    var init = function () {
    _setUpListeners();

    // то, что должно произойти сразу
    };

    var _setUpListeners = function () {
    $(window).on('mousemove', _moveLayers);
    // прослушка событий...
    };

    var _moveLayers = function (e) {
    var mouse_dx = e.pageX,
    mouse_dy = e.pageY,
    w = (window.innerWidth / 2) - mouse_dx,
    h = (window.innerHeight / 2) - mouse_dy;

    layer.map(function (key, value) {
    var bottomPosition = ((window.innerHeight / 2) * ((key + 1) / 100)),
    widthPosition = w * ((key + 1) / 100),
    heightPosition = h * ((key + 1) / 100);

    $(value).css({
    'bottom': '-' + bottomPosition + 'px',
    'transform': 'translate3d(' + widthPosition + 'px, ' + heightPosition + 'px, 0px)'
    });
    });
    };

    return {
    init: init
    };

    })();

    myModule.init();
    myMouseParallax.init();
  3. VasiliuKr revised this gist Oct 9, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion module.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ var myModule = (function () {

    var _setUpListeners = function () {
    // прослушка событий...
    }
    };

    return {
    init: init
  4. VasiliuKr created this gist Aug 26, 2016.
    18 changes: 18 additions & 0 deletions module.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    var myModule = (function () {

    var init = function () {
    _setUpListeners();
    // то, что должно произойти сразу
    };

    var _setUpListeners = function () {
    // прослушка событий...
    }

    return {
    init: init
    };

    })();

    myModule.init();