M
M
Maxim Voronkov2016-11-14 22:38:24
css
Maxim Voronkov, 2016-11-14 22:38:24

Appearance of blocks when clicking on a link, hiding when clicking again + add / remove a class?

Dear colleagues, there is a code https://jsfiddle.net/orsc3xs7/
This code is missing, switching the visibility of the submenu and hiding the submenu when clicked again. And closing the submenu when clicking on an empty space

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Dvoryanov, 2016-11-16
@Raxen

You have very specific markup for implementing tabs, but nevertheless https://jsfiddle.net/orsc3xs7/6/
css

.nav-service {
  padding: 0;
  margin: 0;
  list-style: none;
  position: relative;
}

.nav-service li {
  float: left;
  margin-left: 10px;
}

.sub-menu {
  position: absolute;
  top: 20px;
  left: 0px;
  visibility: hidden;
  opacity: 0;
  transition: all ease 0.2s
}

.active+.sub-menu {
  visibility: visible;
  opacity: 1;
}

jQuery
$('.nav-button').click(function(e) {
  e.stopPropagation();
  e.preventDefault();
  $('.nav-button').not(this).removeClass('active');
  $(this).addClass('active').next().delay(200).show();
});

$('html, .close').click(function() {
  if ($('.nav-button.active').length > 0) {
    $('.nav-button').removeClass('active').next().delay(200).hide()
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question