jqueryvariablespluginsfullpage.js

How to use variables in option parameters for a plugin (like fullpage.js)?


I've been looking for hours to find the answer of my problem, but could'nt find anything usefull.

I'm using the fullpage.js plugin, one of the various option is "anchors". I'd like to use this one but I'll never know the link's names that I've to put in it. They can change in number and names aswell.

So I store all the names I need in a array, then I change this array into a string to use it in the anchors option.

var data_anchors = $('.elements').map(function(){
        return $(this).data('menuanchor');
        }).get(),
        anchors_array = [];
$.each(data_anchors, function(id,val) {                    
     var str = "'" + val + "'";
     anchors_array.push(str);
});

var anchors_var = anchors_array.join(", ");

I've tested the output with alert() and it is perfect, but the plugin/jquery doesn't recognize it, and throw an error :

$(".slide").fullpage({
  // //Navigation
  anchors:[anchors_str],
.....

Error : Syntax error, unrecognized expression: #'link_name1', 'link_name2', 'link_name3'

If write all the link's names manually it works.

Where is the catch? How to make it work?

Thanks for your help


Solution

  • fullpage expects an array of strings, not an array with one concatenated string.

    $(".slide").fullpage({
        // //Navigation
        anchors: $('.elements').map(function() {
            return $(this).data('menuanchor');
        }).get(),
        .....
    });