Streaming live at 10am (PST)

Make 'overflow' --> 'auto' on Second Click

#1

How do I change this code snippet so instead of clicking on ‘.close’ I would like to click a second time on ‘.project-name-wrapper’ to make ‘overflow’ --> ‘auto’?

Webflow.push(function() {
  $('.project-name-wrapper').click(function(e) {
    e.preventDefault();
	$('body').css('overflow', 'hidden');
  });

  $('.close').click(function(e) {
    e.preventDefault();
	$('body').css('overflow', 'auto');
  });
});
0 Likes

#2

Try this:

<script>
var timesClicked = 0;

$("#menu_button").click(function() {
  timesClicked++;

  if (timesClicked % 2 == 0) {
    //run on each second click
     e.preventDefault();
     $('body').css('overflow', 'auto');
     console.log("second" + timesClicked);
  } else {
    //run on each first click
    e.preventDefault();
    $('body').css('overflow', 'hidden');
    console.log("first" + timesClicked);
  }
});
</script>

Anyway, no way to answer “in general” (Not related to your code/project). Sometimes the counter is wrong (If also there is “Close” button -or- close by esc key and so on). This code is very basic.

https://codepen.io/ezra_siton/pen/ROjQKx?editors=1111

2 Likes

#3

Thanks this works great!

(Just had to define function(e) in line #4.)

1 Like