Created
October 8, 2017 23:59
-
-
Save dpmango/607111002c1ae3ca5a7d60dacdef4391 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
// TELEPORT PLUGIN | |
$('[js-teleport]').each(function (i, val) { | |
var self = $(val) | |
var objHtml = $(val).html(); | |
var target = $('[data-teleport-target=' + $(val).data('teleport-to') + ']'); | |
var conditionMedia = $(val).data('teleport-condition').substring(1); | |
var conditionPosition = $(val).data('teleport-condition').substring(0, 1); | |
if (target && objHtml && conditionPosition) { | |
_window.resized(100, function () { | |
teleport() | |
}) | |
function teleport() { | |
var condition; | |
if (conditionPosition === "<") { | |
condition = _window.width() < conditionMedia; | |
} else if (conditionPosition === ">") { | |
condition = _window.width() > conditionMedia; | |
} | |
if (condition) { | |
target.html(objHtml) | |
self.html('') | |
} else { | |
self.html(objHtml) | |
target.html("") | |
} | |
} | |
teleport(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment