I am wondering if there is a way to give a reader the option to close a drop-down at the bottom of the drop-down so they don't have to scroll back to the top? I'm writing a tutorial that has a few drop-down sections, so I might like to have the option for a reader to click "Close" (or something similar) at the bottom to collapse the section they're in before they move to the next section. Any ideas?
Thanks!
Close option at the end of a drop-down
-
Rene Severens
- Sr. Propeller Head
- Posts: 210
- Joined: Mon Sep 19, 2011 2:06 am
- Location: Netherlands - Zoetermeer
- Contact:
Re: Close option at the end of a drop-down
Hi,
I thought I had seen this before, entered by someone else:
Create a "drowdownclose.js" with the next lines and store it in the resource folder (for example in a new created folder named "Scripts")
$(document).ready(function(){
$(".dropDownBody").append("<a href='javascript:void(0);' class='dropDownClose'>(Close)</a>").click(function() {
$(this).parents(".dropDown").find(".dropDownHotspot").click();
});
});
and in the <head> section of the master page add this:
<script src="../Scripts/dropdown.js">
</script>
And this works, BUT ... (and that is why I would like to respond on this) ... it has a slight side-effect: If clicked ANYWHERE in the opened dropdown, the dropdown is closed.
So why show a hyperlink (Close) ? Maybe the script can be changed so it actually works only when clicked the hyperlnk? I am not a script genius...
Greetings,
Rene Severens
I thought I had seen this before, entered by someone else:
Create a "drowdownclose.js" with the next lines and store it in the resource folder (for example in a new created folder named "Scripts")
$(document).ready(function(){
$(".dropDownBody").append("<a href='javascript:void(0);' class='dropDownClose'>(Close)</a>").click(function() {
$(this).parents(".dropDown").find(".dropDownHotspot").click();
});
});
and in the <head> section of the master page add this:
<script src="../Scripts/dropdown.js">
</script>
And this works, BUT ... (and that is why I would like to respond on this) ... it has a slight side-effect: If clicked ANYWHERE in the opened dropdown, the dropdown is closed.
So why show a hyperlink (Close) ? Maybe the script can be changed so it actually works only when clicked the hyperlnk? I am not a script genius...
Greetings,
Rene Severens
"The numbers are strange today; they somehow do not seem to add up."
Re: Close option at the end of a drop-down
Yep, I posted a reply, but deleted it because it had a few problems, which I didn't have time to fix properly at the time.
You could try this instead, which seems to work for me (even with nested dropdowns) in a HTML5 target:
You can change the (Close) text in the script, and format it by adding a.dropDownClose {} to your CSS.
The script adds a (Close) link to every .dropDownBody, and if you click on (Close) then it will click the corresponding .dropDownHotspot link.
You could try this instead, which seems to work for me (even with nested dropdowns) in a HTML5 target:
Code: Select all
$(document).ready(function(){
$(".dropDownBody").append("<a href='javascript:void(0);' class='dropDownClose'>(Close)</a>");
$(".dropDownClose").click(function() {
$(this).parent().prev(".dropDownHead").children(".dropDownHotspot").click();
});
});The script adds a (Close) link to every .dropDownBody, and if you click on (Close) then it will click the corresponding .dropDownHotspot link.
-
Rene Severens
- Sr. Propeller Head
- Posts: 210
- Joined: Mon Sep 19, 2011 2:06 am
- Location: Netherlands - Zoetermeer
- Contact:
Re: Close option at the end of a drop-down
Hi Dave,
Thanks!
This works perfect!
Thank you very much!
Rene Severens
Thanks!
This works perfect!
Thank you very much!
Rene Severens
"The numbers are strange today; they somehow do not seem to add up."
Re: Close option at the end of a drop-down
I've posted a solution for adding a close link to both dropdowns and togglers:
viewtopic.php?f=12&t=28079
viewtopic.php?f=12&t=28079
Re: Close option at the end of a drop-down
Thanks Dave and Rene! I followed these steps and got the Close link in my drop-downs!