Last active
December 17, 2015 04:28
-
-
Save laurendavissmith/5550481 to your computer and use it in GitHub Desktop.
several @koken pulse snippets
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
<style type="text/css"> | |
.pulse-arrow { position: absolute; top: 50%; margin-top: -52px; z-index: 1000; font-size: 70px; color: #fff; cursor: pointer; opacity: .75; font-weight: bold; } | |
.pulse-left { left: 10px; } | |
.pulse-right { right: 10px; } | |
</style> | |
<script> | |
(function() { | |
var leftArr = $('<div class="pulse-left pulse-arrow" data-action="next" />').html('⟨'), | |
rightArr = $('<div class="pulse-right pulse-arrow" data-action="previous" />').html('⟩'), | |
arrowSelector = '.pulse-left, .pulse-right', | |
currentItem; | |
var checkMousePos = function(e) { | |
var container = currentItem.find('img').parent(), | |
offset = container.offset(); | |
if (e.clientX < offset.left || e.clientX > container.width() + offset.left || e.clientY < offset.top || e.clientY > container.height() + offset.top) { | |
cleanUpArrows(); | |
} | |
} | |
var setupHandler = function() { | |
$(document) | |
.off('.pulseArrows') | |
.on('click.pulseArrows', arrowSelector, function(e) { | |
lastMousePos = { | |
clientX: e.clientX, | |
clientY: e.clientY | |
} | |
pulse[$(this).data('action')](); | |
}); | |
} | |
var addArrow = function(which) { | |
cleanUpArrows(); | |
if (which === 'left') { | |
this.append(leftArr); | |
} else { | |
this.append(rightArr); | |
} | |
setupHandler(); | |
} | |
var cleanUpArrows = function() { | |
$(arrowSelector).remove(); | |
} | |
pulse.on('transitionend', function(e) { | |
cleanUpArrows(); | |
currentItem = e.dom; | |
}); | |
pulse.on('contentmousemove', function(e) { | |
if (!e.dom) { return false; } | |
if (e.cursor.percentageX > 50 && !$('.pulse-right').length) { | |
addArrow.call(e.dom.find('img').parent(), 'right'); | |
} else if (e.cursor.percentageX < 50 && !$('.pulse-left').length) { | |
addArrow.call(e.dom.find('img').parent(), 'left'); | |
} | |
}); | |
$(document).on('mousemove', pulse.context, function(e) { | |
if (currentItem) { checkMousePos(e); } | |
}); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment