首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Foundation中有条件地关闭JS插件?

如何在Foundation中有条件地关闭JS插件?
EN

Stack Overflow用户
提问于 2015-04-22 05:57:23
回答 1查看 217关注 0票数 2

使用jQuery,我尝试根据屏幕大小有条件地加载Magellan sticky nav plugin of the Foundation framework

window width > 640px ==>使用指定选项加载麦哲伦

window width < 640px ==>关闭麦哲伦

调整大小事件似乎会触发,但插件似乎没有off选项。

我得到了以下JS:

代码语言:javascript
复制
$(document).ready(function() {

/* foundation magellan scroller*/

    function checkWidth() {

        var $windowSize = $(window).width();

        if ( $windowSize > 640 ) {

            $(document).foundation({

                "magellan-expedition": {
                  active_class: 'active', // specify the class used for active sections
                  threshold: 0, // how many pixels until the magellan bar sticks, 0 = auto
                  destination_threshold: 50, // pixels from the top of destination for it to be considered active
                  throttle_delay: 50, // calSculation throttling to increase framerate
                  fixed_top: 75, // top distance in pixels assigend to the fixed element on scroll
                  offset_by_height: true // whether to offset the destination by the expedition height. Usually you want this to be true, unless your expedition is on the side.
                }

            });

        } else {

            $(document).foundation('magellan', 'off');

        }
    }

    // Execute on load
    checkWidth();

    // Bind event listener
    $(window).resize(checkWidth);

});
EN

回答 1

Stack Overflow用户

发布于 2015-04-23 01:42:30

您没有html标记,但是您可以通过删除data属性来删除或关闭麦哲伦粘性标记

如果您的html如下所示

在您的else语句中删除att.

代码语言:javascript
复制
 else {

          $(".navi-f").removeAttr("data-magellan-expedition");

    }

这样就像关闭插件一样

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29783895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档