Foundation-sites: [Magellan] Get the section id when we scroll to it?

Created on 15 Jan 2018  ·  6Comments  ·  Source: foundation/foundation-sites

Is it possible to get the section id when we scroll to it? Any data in magellan events?

question

Most helpful comment

@ncoden

This work, check it

$('#magellan').on('update.zf.magellan', function (ev, elem) { console.log(elem[0].getAttribute('href')); });

All 6 comments

See the Javascript Reference of Magellan:

Name | Description
-- | --
update.zf.magellan | Fires when magellan is finished updating to the new active element.

For example:
js $('#myMagellan').on('update.zf.magellan', function($elem) { console.log('The magellan is now at ' + $elem.attr('id')); });

@ncoden

Error in console:
$elem.attr is not a function

Also, I do not see the id in the object. for example:

$('#magellan').on('update.zf.magellan', function(elem) {
 console.log(elem);
});

You can try:
```js
$('#magellan').on('update.zf.magellan', function(elem) {
elem[0].getAttribute('id');
});

@ncoden

elem[0] is undefined 8(

@ncoden

This work, check it

$('#magellan').on('update.zf.magellan', function (ev, elem) { console.log(elem[0].getAttribute('href')); });

It's bad that the "update.zf.magellan" event happens more than once (4 and more more...) with manual scrolling (not by the menu link). UPD: with click on menu - it happens 2 times..
image

I have full height section of window. If I do a check on the id section (for example - to show/hide some block when we switched to it), then this block is hide/show several times. It looks like i need to use a third-party plug-in to determine what's in the browser vieweport now 8(

Was this page helpful?
0 / 5 - 0 ratings