Показать сообщение отдельно
  #19 (permalink)  
Старый 26.02.2018, 19:53
Аватар для j0hnik
Профессор
Отправить личное сообщение для j0hnik Посмотреть профиль Найти все сообщения от j0hnik
 
Регистрация: 01.12.2016
Сообщений: 3,650

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
	<style>
		.active{
			background-color: red;
		}
	</style>
</head>
<body>
	<div class="fn_switch" data-name="11">1</div><div></div>
	<div class="fn_switch" data-name="12">2</div><div></div>
	<div class="fn_switch" data-name="13">3</div><div></div>
	<div class="fn_switch" data-name="14">4</div><div></div>
	<div class="fn_switch" data-name="15">5</div><div></div>
	<div class="fn_switch" data-name="16">6</div><div></div>
	<div class="fn_switch" data-name="17">7</div><div></div>

	<script>
		$(function(){
			
			$('.fn_switch').click(function(e){

				e.preventDefault();

				$(this).next().slideToggle(300);


				if ($(this).hasClass('active')) {
					$(this).removeClass('active');
				}
				else {
					$(this).addClass('active');
				}

				var arr = $.map($('.fn_switch'), function(el, i){
					if($(el).hasClass('active')) return $(el).attr('data-name');
				});

				localStorage.setItem('a', JSON.stringify(arr));
			});

				$('.fn_switch').filter(function(i){
					return 	JSON.parse(localStorage.getItem('a')).includes($(this).attr('data-name'));
				}).addClass('active').next().show();
		});

	</script>
</body>
</html>


	</script>
</body>
</html>

Последний раз редактировалось j0hnik, 26.02.2018 в 20:18.
Ответить с цитированием