How to disable JavaScript function after clicking?

I have a page, and when you scroll it, objects (container ...) become visible. I also have projects. So when you click on one of them, my page scrolls up. And I want to disable this feature that I mentioned earlier (showing to disable scrolling!).

$(document).ready(function(){
var offsetActivity = (1);
var wScroll = ($(window).scrollTop());
var wHeight = ($(window).innerHeight());
var thirdHeight = (wHeight/1.3);
$('.secondic > .row > a > .one-half > p').click(function(offsetActivity){
  var offsetActivity = (0);
  var projBack = $(this).parent().css('background-image');
  var parent = $(this).parent().attr('id');
  var textAbout = $('#'+ parent +' > p.about-photo').text();
$('header').css('background-image', ''+ projBack +'');
$('header > .headerCont > h5').replaceWith('<h5>'+ textAbout +'</h5>');
    setTimeout(function(){
      $('.container').removeClass('offset-done');
      $('.container').children().removeClass('offset-done');
    }, 2000);
});
if(offsetActivity = (1)){
$(window).scroll(
  function(){
    var wScroll = ($(window).scrollTop());
    var wHeight = ($(window).innerHeight());
    var thirdHeight = (wHeight/1.3);
    console.log(wHeight, wScroll, thirdHeight);
      if(wScroll > (($('.container').offset().top)-thirdHeight)){
        $('.container').addClass('offset-done');
      }
      if(wScroll > (($('.window').offset().top)-thirdHeight)){
        $('.window').addClass('offset-done');
      }
  });
});

so how to disable this function when i click on my P? I also want to not be able to turn it on after the project is completed

+4
source share
3 answers

You can disable the event handler in jquery with off().

.off() , .(). . . .off() , . , , .

jquery api: http://api.jquery.com/off/

$(window).off('scroll');, .

+3

click $window.off('scroll'); $window.unbind('scroll');

+2

jquery fucntion .off , .on $(window).on( 'scroll', 'body', function(){ ... });

$(window).off( 'scroll', 'body');

+1

Source: https://habr.com/ru/post/1610636/


All Articles