JohnK
September 21, 2022, 6:57pm
1
Hey Softr community!
I’m trying to use a bit of custom code from the unlock-softr page. It’s supposed to expand/collapse blocks when another block is clicked.
The issue I am having is that on page load, the block that is supposed to be collapsed is expanded.
Is there a way to fix this code so that the block that is supposed to be collapsed starts out that way?
Code:
<script>
const interval = setInterval(function () {
if (typeof($) == "function") {
$("#other1").click(function () {
$("#list1").toggle("slow");
});
clearInterval(interval);
}
}, 100)
</script>
Link to guide:
Thanks in advance!
Hi John,
Strange behaviour, as when clicked, the block should vanish. If you click again it should appear again.
The block you want to hide and show has something specific?
Or do you want that behaviour on page load like this process here ?
page load = hidden
click = show
re-click = hide again
1 Like
JohnK
September 21, 2022, 8:34pm
3
Hey @matthieu_chateau ,
Exactly, what you’re describing is what I’m looking for:
page load = hidden
click = show
re-click = hide again
There should be something like this to be added
<script>
window.onload = function(){
document.getElementById("#list1").style.display='none';
};
</script>
But this is beyond my capabilities for now
@dcoletta , this one is for you
2 Likes
JohnK
September 21, 2022, 11:08pm
5
Gave this a try, but no success. I appreciate the attempt!
Suzie
September 23, 2022, 4:49pm
6
@dcoletta perhaps you can help here
Thanks in advance.
I was able to get the effect you’re looking for with this change:
<script>
const interval = setInterval(function () {
if (typeof($) == "function") {
$("#hero2").hide();
$("#hero1").click(function () {
$("#hero2").toggle("slow");
});
clearInterval(interval);
}
}, 100)
</script>
4 Likes
JohnK
September 23, 2022, 7:55pm
8
@dcoletta Thanks so much! This works perfectly!!
JohnK
September 23, 2022, 8:24pm
9
One follow up, in case this is useful for anyone else, I was able to modify this script to allow me to:
Hide/Show multiple blocks at once
Have multiple Hide/Show effects on one page
<script>
const interval = setInterval(function () {
if (typeof($) == "function") {
$("#aws1").hide();
$("#aws2").hide();
$("#showaws").click(function () {
$("#aws1").toggle("slow");
$("#aws2").toggle("slow");
});
$("#reviewform").hide();
$("#showreview").click(function () {
$("#reviewform").toggle("slow");
});
clearInterval(interval);
}
}, 100)
</script>
3 Likes
JohnK
September 23, 2022, 10:16pm
10
@dcoletta @matthieu_chateau
I’m having trouble showing lists using this script. Is there a trick to making that work?
List Details work perfectly.
Suzie
September 24, 2022, 3:10pm
11
Thanks so much for the fast response
JohnK
September 25, 2022, 6:58pm
12
Figured out a super hacky solution here.
It seems like what was happening is that the height of the list items was being lost in the dynamic fields.
What I did was insert dividers with a bunch of padding on top to create cell height allowing the dynamic information to show. You can then make the dividers the same color as the background to make them invisible.
1 Like
Suzie
September 26, 2022, 6:37am
13
Thanks for sharing @JohnK
1 Like