Last active
August 29, 2015 14:11
-
-
Save artpolikarpov/88515451c5daf4fc2869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// после 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