Skip to content

Instantly share code, notes, and snippets.

@artpolikarpov
Last active August 29, 2015 14:11
Show Gist options
  • Save artpolikarpov/88515451c5daf4fc2869 to your computer and use it in GitHub Desktop.
Save artpolikarpov/88515451c5daf4fc2869 to your computer and use it in GitHub Desktop.
// после scrollyeah.js
$(function () {
// ↓ селектор активного блока
$('.scrollyeah .one.active').each(function () {
var $current = $(this);
var $shaft = $current.parents('.scrollyeah__shaft');
var $scrollyeah = $current.parents('.scrollyeah');
if (!$current.length || !$shaft.length || !$scrollyeah.length) {
return console.warn('Незачем крутить :-/');
}
var currentLeft = $current.position().left;
var currentWidth = $current.outerWidth() + $current.css('margin-left').replace('px', '')*2;
var shaftWidth = $shaft.outerWidth();
var scrollyeahWidth = $scrollyeah.innerWidth();
var shaftLeft = Math.min(0, Math.max(-shaftWidth + scrollyeahWidth, -currentLeft + scrollyeahWidth/2 - currentWidth/2));
// аццкий хак, АПИ-то нет
$shaft.css({left: shaftLeft}).trigger(jQuery.Event('mousedown', {which: 1, pageX: 0, targetTouches: [{pageX: 0, pageY: 0}]}));
$(document).trigger('mouseup');
$(window).trigger('resize');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment