Reputation: 433
I have a page, and when you scroll that, objects (container...) become visible. Also I have projects. So when you click on one of them, my page scrolls up. And i want to disable that function that I told before (showing up, not to disable scroll!).
$(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 that function when i click on my P? Also i want ot be able to turn it on again after i close the project
Upvotes: 4
Views: 119
Reputation: 536
to use jquery fucntion .off
you need active then using .on
$(window).on( 'scroll', 'body', function(){
...
});
when click function
$(window).off( 'scroll', 'body');
Upvotes: 1
Reputation: 3317
You can unset an event handler in jquery with off()
.
The .off() method removes event handlers that were attached with .on(). See the discussion of delegated and directly bound events on that page for more information. Calling .off() with no arguments removes all handlers attached to the elements. Specific event handlers can be removed on elements by providing combinations of event names, namespaces, selectors, or handler function names.
from the jquery api: http://api.jquery.com/off/
In your case you should use $(window).off('scroll');
to remove the event handler for your scroll event from window object.
Upvotes: 3
Reputation: 554
Within your click
function, use $window.off('scroll');
or $window.unbind('scroll');
Upvotes: 2