Comments (6)
The only way I was successful was by adding a setTimeout to trigger the open later.
// See if the hash is within this accordion so we can open it
if(window.location.hash != '') {
accordion.folds.forEach(function (fold) {
if(fold.heading.getAttribute('id') == window.location.hash.substr(1)) {
window.setTimeout(function () {
fold.open = true;
}, 500);
}
});
}
I typically dislike using it but I am not seeing a way to tie into an event for when Accordion is finished loading to trigger the code above.
Regardless I think this will be good enough for my situation. Feel free to close and thank you for the help! :)
from accordion.
Does the hash match an element ID in the page at startup? If so, the scrolling will be automatic (and not terribly pretty). Things also get a bit tricky when nested accordions are involved... 🤔
I really need to improve deep-linking support...
from accordion.
@Alhadis Yea I guess the scrolling part isn't as important since the browser can automatically handle it, really depends on where you put the ID if it's visible or not to the user. In a case I'm playing around with, I'm putting it on the accordion links so they are all visible.
So my question is how do you open an accordion item once you have the element and the accordion is applied already?
if(window.location.hash != '') {
let item = document.getElementById(window.location.hash.substr(1));
// Open item somehow...
}
from accordion.
Every Accordion
instance has a .folds
property which provides access to the Fold
instances that control the physical DOM element. Setting a Fold
's .open
property to false
will close it; similarly, setting it to true
will open it.
The rest of the API docs should hopefully explain the rest. :-)
from accordion.
Great, thank you for the help! I have it working now with this code. I have an overall loop checking for multiple accordion instances and setting the accordion instance to accordion
.
// See if the hash is within this accordion so we can open it
if(window.location.hash != '') {
accordion.folds.forEach(function (fold) {
if(fold.heading.getAttribute('id') == window.location.hash.substr(1)) {
fold.open = true;
}
});
}
The only thing I noticed is it seems the height of the fold is calculated differently when using fold.open = true
vs clicking it. Not a huge deal, but it looks a little cramped. Any insights?
Deep Link
Clicked
from accordion.
Sometimes the height of a fold's content can change, such as when line-wrapping occurs, or when images and stuff load and push content further down. In these scenarios, call the .fit()
method of the opened fold after a delay. You might have to do this a few times if the page hasn't finished loading.
from accordion.
Related Issues (19)
- Rewrite code in ECMAScript 6 HOT 2
- Update height if contents change HOT 6
- Enter and spacebar to open/close accordion item HOT 22
- README - bundled demos link broken HOT 1
- Where is demo? HOT 5
- Loaded event? HOT 23
- No easy way to add/remove folds after construction HOT 3
- Anyway to access the click event? HOT 2
- Responsive heightOffset HOT 3
- Height not updating when closing an accordion nested in another
- Feature: Only open one accordion at a time, collapse others? HOT 3
- Incorrect heights set for nested accordions with pre-opened folds
- Borders aren't considered when calculating fold heights HOT 1
- To-do list
- Option to allow only one fold to be open at a time HOT 3
- Strange type rendering issue with Chrome 55 / Mac 10.10.5 HOT 14
- Doesn't work on IE HOT 11
- Great Plugin HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accordion.