Created
December 6, 2016 09:06
-
-
Save Mons1eurEnzo/df53b903e70c4fd5612ba33137b7c7c7 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
$(document).ready(function () { | |
//при открытии панели пользователем, записываем значение её атрибута id в LocalStorage (ключ bootstrapAccordion) | |
$("#bootstrap").on('shown.bs.collapse', function () { | |
var active = $("#bootstrap .in").attr('id'); | |
localStorage.setItem("bootstrapAccordion", active); | |
}); | |
//при закрытии панели удаляем bootstrapAccordion из LocalStorage | |
$("#bootstrap").on('hidden.bs.collapse', function () { | |
localStorage.removeItem("bootstrapAccordion"); | |
}); | |
// после загрузки страницы получаем последнюю активную панель из LocalStorage | |
var last = localStorage.getItem("bootstrapAccordion"); | |
// если оно там есть, то открываем её | |
if (last != null) { | |
$("#bootstrap .panel-collapse").removeClass('in'); | |
$("#" + last).addClass("in"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment