Javascript.RU

Создать новую тему Ответ
 
Опции темы Искать в теме
  #1 (permalink)  
Старый 04.11.2016, 17:36
Новичок на форуме
Отправить личное сообщение для r1pt1d3 Посмотреть профиль Найти все сообщения от r1pt1d3
 
Регистрация: 04.11.2016
Сообщений: 2

Jquery, поменять иконку
Добрый вечер, сижу ломаю голову, не могу понять элементарную вещь.
Когда закрываю открытое окно, то иконка не меняется на плюс. Всё остальное работает отлично. Вот собственно код.

HTML-код:
<div id="faq_info_holder">
    <div class="faq_collumn">
        <a class="faq_info">
            <div>
                <p class="faq_name">Tempor incididunt
			<i class="material-icons-add_circle"></i>
	       </p>
               <span class="hiden_faq">
               ....
               </span>
            </div>
        </a>
    </div>
</div>



Код:
.faq_collumn{
		height: 522px;
		width: 350px;
		float: left;
		margin-left: 40px;
	}
	.faq_info{
		width: 350px;
		height: auto;
		min-height: 65px;
		max-height: 350px;
		border-radius: 4px;
		box-shadow: 0 0 10px rgba(0,0,0,0.6);
		background-color: #FF4538;
		float: left;
		margin-bottom: 40px;
		cursor: pointer;
	}
	#faq_info_holder{
		width: 1200px;
		margin: auto;
	}
	.faq_name{
		font: 22px georgia;
		color: white;
		margin: 0;
		margin-left: 25px;
		margin-top: 20px;
	}
	.material-icons-add_circle{
		float: right;
		color: white;
		font-size: 32px;
		margin-right: 15px;
		margin-top: -4px;
	}
	.material-icons-remove_circle{
		float: right;
		color: white;
		font-size: 32px;
		margin-right: 15px;
		margin-top: -4px;
	}
	.hiden_faq{
		font: 16px georgia;
		color: white;
		float: left;
		margin-left: 25px;
		margin-right: 55px;
		margin-bottom: 20px;
		display: none;
	}
	.active{
		background: #DD3C30;
	}

И непосредственно Jquery:

$(".faq_info").click(function(){

		$(this).toggleClass("active").find(".hiden_faq").slideToggle("normal");

		if ($(".faq_info").hasClass("active")){
			$(".faq_info").not(this).removeClass("active").find(".hiden_faq").slideUp("normal");

			$(".faq_info").find(".material-icons-remove_circle").addClass("material-icons-add_circle").removeClass("material-icons-remove_circle");
		}

		$(this).find(".material-icons-add_circle").addClass("material-icons-remove_circle").removeClass("material-icons-add_circle");


	});



P.S. док.реди прописан офк.
Ответить с цитированием
  #2 (permalink)  
Старый 04.11.2016, 20:29
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

r1pt1d3,
количество классов избыточно ...
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
   .faq_collumn{
		height: 522px;
		width: 350px;
		float: left;
		margin-left: 40px;
	}
	.faq_info{
		width: 350px;
		height: auto;
		min-height: 65px;
		max-height: 350px;
		border-radius: 4px;
		box-shadow: 0 0 10px rgba(0,0,0,0.6);
		background-color: #FF4538;
		float: left;
		margin-bottom: 40px;
		cursor: pointer;
	}
	#faq_info_holder{
		width: 1200px;
		margin: auto;
	}
	.faq_name{
		font: 22px georgia;
		color: white;
		margin: 0;
		margin-left: 25px;
		margin-top: 20px;
	}
	.material-icons-add_circle{
		float: right;
		color: white;
		font-size: 32px;
		margin-right: 15px;
		margin-top: -4px;
	}
    .material-icons-add_circle:after{
      content: "+";
    }

	.material-icons-remove_circle{
		float: right;
		color: white;
		font-size: 32px;
		margin-right: 15px;
		margin-top: -4px;
	}
    .material-icons-remove_circle:after{
      content: "-";
    }

	.hiden_faq{
		font: 16px georgia;
		color: white;
		float: left;
		margin-left: 25px;
		margin-right: 55px;
		margin-bottom: 20px;
		display: none;
	}
	.active{
		background: #DD3C30;
	}
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
   <script>
$(function() {
    $(".faq_info").click(function() {
        $(this).toggleClass("active").find(".hiden_faq").slideToggle("normal");
        $(".faq_info").not(this).removeClass("active").find(".hiden_faq").slideUp("normal");
        $(".faq_info").not(this).find(".material-icons-remove_circle").addClass("material-icons-add_circle").removeClass("material-icons-remove_circle");
        if ($(this).hasClass("active")) $(this).find(".material-icons-add_circle").addClass("material-icons-remove_circle").removeClass("material-icons-add_circle");
        else $(this).find(".material-icons-remove_circle").addClass("material-icons-add_circle").removeClass("material-icons-remove_circle")
    })
});
  </script>
</head>

<body>
<div id="faq_info_holder">
    <div class="faq_collumn">
        <a class="faq_info">
            <div>
                <p class="faq_name">Tempor incididunt
      <i class="material-icons-add_circle"></i>
         </p>
               <span class="hiden_faq">
               ....
               </span>
            </div>
        </a>
    </div>
</div>
<div id="faq_info_holder">
    <div class="faq_collumn">
        <a class="faq_info">
            <div>
                <p class="faq_name">Tempor incididunt
      <i class="material-icons-add_circle"></i>
         </p>
               <span class="hiden_faq">
               ....
               </span>
            </div>
        </a>
    </div>
</div>

</body>
</html>
Ответить с цитированием
  #3 (permalink)  
Старый 04.11.2016, 20:38
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

r1pt1d3,
смена иконки без дополнительного класса
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
   .faq_collumn{
		height: 522px;
		width: 350px;
		float: left;
		margin-left: 40px;
	}
	.faq_info{
		width: 350px;
		height: auto;
		min-height: 65px;
		max-height: 350px;
		border-radius: 4px;
		box-shadow: 0 0 10px rgba(0,0,0,0.6);
		background-color: #FF4538;
		float: left;
		margin-bottom: 40px;
		cursor: pointer;
	}
	#faq_info_holder{
		width: 1200px;
		margin: auto;
	}
	.faq_name{
		font: 22px georgia;
		color: white;
		margin: 0;
		margin-left: 25px;
		margin-top: 20px;
	}
	.material-icons-add_circle{
		float: right;
		color: white;
		font-size: 32px;
		margin-right: 15px;
		margin-top: -4px;
	}
    .material-icons-add_circle:after{
      content: "+";
    }


   .active .material-icons-add_circle:after{
      content: "-";
    }

	.hiden_faq{
		font: 16px georgia;
		color: white;
		float: left;
		margin-left: 25px;
		margin-right: 55px;
		margin-bottom: 20px;
		display: none;
	}
	.active{
		background: #DD3C30;
	}
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
   <script>
$(function() {
    var info = $(".faq_info");
    info.on("click",function() {
        $(this).toggleClass("active").find(".hiden_faq").slideToggle("normal");
        info.not(this).removeClass("active").find(".hiden_faq").slideUp("normal");
    })
});
  </script>
</head>

<body>
<div id="faq_info_holder">
    <div class="faq_collumn">
        <a class="faq_info">
            <div>
                <p class="faq_name">Tempor incididunt
      <i class="material-icons-add_circle"></i>
         </p>
               <span class="hiden_faq">
               ....
               </span>
            </div>
        </a>
    </div>
</div>
<div id="faq_info_holder">
    <div class="faq_collumn">
        <a class="faq_info">
            <div>
                <p class="faq_name">Tempor incididunt
      <i class="material-icons-add_circle"></i>
         </p>
               <span class="hiden_faq">
               ....
               </span>
            </div>
        </a>
    </div>
</div>

</body>
</html>
Ответить с цитированием
  #4 (permalink)  
Старый 04.11.2016, 20:56
Новичок на форуме
Отправить личное сообщение для r1pt1d3 Посмотреть профиль Найти все сообщения от r1pt1d3
 
Регистрация: 04.11.2016
Сообщений: 2

Спасибо, использовал первый вариант.

"Количество классов избыточно", лучше использовать id там где классы не требуются? В чем преимущество?
Ответить с цитированием
  #5 (permalink)  
Старый 04.11.2016, 21:24
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,075

Сообщение от r1pt1d3
лучше использовать id там где классы не требуются
чаще наоборот id не требуется
Сообщение от r1pt1d3
В чем преимущество?
2 строки скрипта без проблем с названими классов или 5 с вырви глаз
Ответить с цитированием
Ответ



Опции темы Искать в теме
Искать в теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Не могу поменять CSS из jQuery fenix_63 jQuery 4 13.09.2016 18:13
Jquery - поменять местами таблицы Sergei-b84 jQuery 14 11.03.2015 20:00
jquery поменять класс taktak Общие вопросы Javascript 3 18.12.2014 12:18
Jquery - поменять местами блоки denlem jQuery 4 09.12.2010 16:00
jQuery поменять CSS цвет для текста при наведении мышью (.text:hover) JooZ jQuery 16 15.11.2010 19:56