css - jQuery toggles active state -
i'm implementing toggles on page http://www.creativusmouse.com/hyperion/html/toggles.html , wanted have toggle button remain orange when it's active. please find bellow css , jquery code used. believe easy achieve. hope me. thank ;)
jquery(window).load(function(){ $('.toggle-view li').click(function () { var text = $(this).children('div.toggle-content'); if (text.is(':hidden')) { text.slidedown('200'); $(this).children('span').html('<i class="icon-minus"></i>'); } else { text.slideup('200'); $(this).children('span').html('<i class="icon-plus"></i>'); } }); });
/* ======================== css ======================== */
.toggle-view { margin:0; padding: 0; list-style-type:none; } .toggle-view li { margin:0px 0px 25px; position:relative; cursor:pointer; display: block; font-weight: bold; text-decoration: none; } .toggle-view h2 { font-size:12px; text-transform:uppercase; margin:0; padding:4px 0 4px 40px; } .toggle-view span { background: none repeat scroll 0 0 #80acb9; color: #fff; font-size: 12px; padding: 2px 4px 2px 2px; position: absolute; left: 0px; top: 0; -webkit-transition: 0.4s ease; -moz-transition: 0.4s ease; -o-transition: 0.4s ease; transition: 0.4s ease; } .toggle-view li:hover h2 { } .toggle-view li:hover span { background: none repeat scroll 0 0; background:#f63; color:#fff; } .toggle-view .toggle-content { box-sizing: content-box; display:none; padding:10px 35px; } .toggle-view ul.square, .toggle-view ul.circle, .toggle-view ul.disc { margin-left:20px; }
add class span element.
in css add class selector span, same hover one:
.activetoggle, .toggle-view li:hover span { background: none repeat scroll 0 0; background:#f63; color:#fff; }
and in javascript add:
$(this).children('span').toggleclass('activetoggle');
i think might work.
here little simplified illustration on jsfiddle
update: updated jsfiddle markup , code, , toggle class on li
element
$('.toggle-view li').click(function () { var text = $(this).children('div.toggle-content'); if (text.is(':hidden')) { text.slidedown('200'); $(this).children('span').html('<i class="icon-minus"></i>'); } else { text.slideup('200'); $(this).children('span').html('<i class="icon-plus"></i>'); } $(this).toggleclass('activetoggle'); });
to simplify little =) css selector .activetoggle span
.
Comments
Post a Comment