I have a contact div that appears fixed on the page. It has its own scroll. I want to hide the main scroll while contact div is activated, and return it when its not.
How to?
Here is my site Read-Only: https://zenus-test.webflow.io/
(how to share your site Read-Only link )
dram
(Alex Dram)
March 11, 2019, 5:51pm
2
Here is how you can do it:
Webflow.push(function() {
$('#open').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'hidden');
});
$('#close').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'auto');
}
}
#open
and #close
are the id’s of your links that open and close your modal
edit: this one is invalid, look further down
1 Like
dram:
Webflow.push(function() { $(‘#open ’).click(function(e) { e.preventDefault(); $(‘body’).css(‘overflow’, ‘hidden’); }); $(‘#close ’).click(function(e) { e.preventDefault(); $(‘body’).css(‘overflow’, ‘auto’); } }
It’s not working.
I’m putting it on Custom Code like this inside a script tag:
Webflow.push(function() {
$('#contact-open').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'hidden');
});
$('#contact-close').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'auto');
}
}
On the console I get this error:
Uncaught SyntaxError: missing ) after argument list
If I add it, then it says:
Webflow is not defined.
dram
(Alex Dram)
March 11, 2019, 6:11pm
4
Ouch. I think I missed a thing here. Please try this
Webflow.push(function() {
$('#open').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'hidden');
});
$('#close').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'auto');
}));
}
edit: still invalid, look even further down.
1 Like
Still doesn’t works. I’m adding the the ID names on the settings for each div. What could be the problem?
dram:
Webflow.push(function() { $(‘#open ’).click(function(e) { e.preventDefault(); $(‘body’).css(‘overflow’, ‘hidden’); }); $(‘#close ’).click(function(e) { e.preventDefault(); $(‘body’).css(‘overflow’, ‘auto’); })); }
I still get this error:
Uncaught SyntaxError: Unexpected token )
dram
(Alex Dram)
March 11, 2019, 7:42pm
8
Dammit
Webflow.push(function() {
$('#open').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'hidden');
});
$('#close').click(function(e) {
e.preventDefault();
$('body').css('overflow', 'auto');
});
});
Sorry, cannot test it myself at the moment so please bear with me!
dram:
Webflow.push(function() { $(‘#open ’).click(function(e) { e.preventDefault(); $(‘body’).css(‘overflow’, ‘hidden’); }); $(‘#close ’).click(function(e) { e.preventDefault(); $(‘body’).css(‘overflow’, ‘auto’); }); });
Now that worked! Thank you!
I understand that code, but the error were simply some typos ?
dram
(Alex Dram)
March 11, 2019, 7:50pm
10
Yes! Need to work on my proper closures seeing power. Literally missed and then misplaced a closing bracket, ugh… so embarrassing!
1 Like