var _menu = $("#menu");
var _block = $("#block");
_menu.click(function () {
/* Высота нашего блока */
var bH = parseFloat($('#block').css('bottom'));
/* Высота родителя блока, по умолчанию берем высоту окна */
var bParentH = $(window).height();
/* Перебираем всех родителей нашего блока (уже отсортированы по близости) */
_block.parents().each(function() {
/* Высота элемента родителя */
var elementH = Math.ceil(parseFloat($(this).css('height')));
/**
* Интересуют только те элементы, у которых заданы:
* - относительное позиционирование
* - высота
*/
if ($(this).css('position') === 'relative' && elementH > 0) {
bParentH = elementH;
/* Выходим из цикла */
return false;
}
});
/* Значение из inline-стилей */
var bInlineHInPercentage = _block[0].style.bottom;
/* Автоматически рассчитываемое значение */
var bCalculatedHInPercentage = Math.ceil(100 * bH / bParentH) + '%';
/* Приоритет отдаем значению из inline-стилей, если таковое есть */
var bHInPercentage = bInlineHInPercentage || bCalculatedHInPercentage;
if (bHInPercentage === '4%') {
_block.animate({
'bottom': '10%'
}, 300);
} else {
_block.animate({
'bottom': '4%'
}, 300);
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.