0

我有一个已本地化的 JSON 编码对象,最终将填写一个 JS 文件以获取选项。选项的预期输出是(默认值和它正在寻找的“类型”的解释):

jQuery(window).load(function() {
    jQuery('.flexslider').flexslider({
        animation: "fade",              //String: Select your animation type, "fade" or "slide"
        slideDirection: "horizontal",   //String: Select the sliding direction, "horizontal" or "vertical"
        slideshow: true,                //Boolean: Animate slider automatically
        slideshowSpeed: 7000,           //Integer: Set the speed of the slideshow cycling, in milliseconds
        animationDuration: 600,         //Integer: Set the speed of animations, in milliseconds
        directionNav: true,             //Boolean: Create navigation for previous/next navigation? (true/false)
        controlNav: true,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
        keyboardNav: true,              //Boolean: Allow slider navigating via keyboard left/right keys
        mousewheel: false,              //Boolean: Allow slider navigating via mousewheel
        prevText: "Previous",           //String: Set the text for the "previous" directionNav item
        nextText: "Next",               //String: Set the text for the "next" directionNav item
        pausePlay: false,               //Boolean: Create pause/play dynamic element
        pauseText: 'Pause',             //String: Set the text for the "pause" pausePlay item
        playText: 'Play',               //String: Set the text for the "play" pausePlay item
        randomize: false,               //Boolean: Randomize slide order
        slideToStart: 0,                //Integer: The slide that the slider should start on. Array notation (0 = first slide)
        animationLoop: true,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
        pauseOnAction: true,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
        pauseOnHover: false,            //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
        controlsContainer: "",          //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
        manualControls: "",             //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
        start: function(){},            //Callback: function(slider) - Fires when the slider loads the first slide
        before: function(){},           //Callback: function(slider) - Fires asynchronously with each slider animation
        after: function(){},            //Callback: function(slider) - Fires after each slider animation completes
        end: function(){}               //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
    });
});

我当前的 JSON 编码对象的 HTML 输出是:

/*<![
    CDATA[
        */varflexslider_vars=[

        ];flexslider_vars={
            "js_animation": "fade",
            "js_slide_direction": "horizontal",
            "js_slideshow": "1",
            "js_slideshow_speed": "7000",
            "js_animation_duration": "600",
            "js_direction_nav": "1",
            "js_control_nav": "1",
            "js_keyboard_nav": "1",
            "js_mousewheel": null,
            "js_prev_text": "Prevous",
            "js_next_text": "Next",
            "js_pause_play": null,
            "js_pause_text": "Pause",
            "js_play_text": "Play",
            "js_randomize": null,
            "js_slide_start": "0",
            "js_animation_loop": "1",
            "js_pause_on_action": "1",
            "js_pause_on_hover": null,
            "js_controls_container": "",
            "js_manual_controls": "",
            "js_start_function": "function(){}",
            "js_before_function": "function(){}",
            "js_after_function": "function(){}",
            "js_end_function": "function(){}"
        };/*
    ]
]>*/

这就是我目前(但未成功)将这些选项添加到 JS 文件的方式:

jQuery(window).load(function() {
    jQuery('.flexslider').flexslider({
        animation: flexslider_vars.js_animation,              //String: Select your animation type, "fade" or "slide"
        slideDirection: flexslider_vars.js_slide_direction,   //String: Select the sliding direction, "horizontal" or "vertical"
        slideshow: flexslider_vars.js_slideshow,                //Boolean: Animate slider automatically
        slideshowSpeed: flexslider_vars.js_slideshow_speed,           //Integer: Set the speed of the slideshow cycling, in milliseconds
        animationDuration: flexslider_vars.js_animation_duration,         //Integer: Set the speed of animations, in milliseconds
        directionNav: flexslider_vars.js_direction_nav,             //Boolean: Create navigation for previous/next navigation? (true/false)
        controlNav: flexslider_vars.js_control_nav,               //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage
        keyboardNav: flexslider_vars.js_keyboard_navjs_mousewheel,              //Boolean: Allow slider navigating via keyboard left/right keys
        mousewheel: flexslider_vars.js_mousewheel,              //Boolean: Allow slider navigating via mousewheel
        prevText: flexslider_vars.js_prev_text,           //String: Set the text for the "previous" directionNav item
        nextText: flexslider_vars.js_next_text,               //String: Set the text for the "next" directionNav item
        pausePlay: flexslider_vars.js_pause_play,               //Boolean: Create pause/play dynamic element
        pauseText: flexslider_vars.js_pause_text,             //String: Set the text for the "pause" pausePlay item
        playText: flexslider_vars.js_play_text,               //String: Set the text for the "play" pausePlay item
        randomize: flexslider_vars.js_randomize,               //Boolean: Randomize slide order
        slideToStart: flexslider_vars.js_slide_start,                //Integer: The slide that the slider should start on. Array notation (0 = first slide)
        animationLoop: flexslider_vars.js_animation_loop,            //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
        pauseOnAction: flexslider_vars.js_pause_on_action,            //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
        pauseOnHover: flexslider_vars.js_pause_on_hover,            //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
        controlsContainer: flexslider_vars.js_controls_container,          //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken.
        manualControls: flexslider_vars.js_manual_controls,             //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
        start: flexslider_vars.js_start_function,            //Callback: function(slider) - Fires when the slider loads the first slide
        before: flexslider_vars.js_before_function,           //Callback: function(slider) - Fires asynchronously with each slider animation
        after: flexslider_vars.js_after_function,            //Callback: function(slider) - Fires after each slider animation completes
        end: flexslider_vars.js_end_function              //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
    });
});

所以 - 问题不在于调用选项本身(这似乎工作正常),它是根据 JS 文件的所需值改变实际输出(字符串、布尔值、整数等),因为截至目前,它是正因为它而做深蹲。我会很感激任何朝着正确方向的推动。谢谢!

4

0 回答 0