首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从smoothState.js添加到购物车按钮和登录/注册链接禁用WooCommerce

如何从smoothState.js添加到购物车按钮和登录/注册链接禁用WooCommerce
EN

Stack Overflow用户
提问于 2017-01-14 11:12:00
回答 1查看 527关注 0票数 1

我刚刚在我目前工作的一家由WooCommerce驱动的商店上实现了smoothState.js。可以通过以下链接找到现场演示:http://demos.oosh.co/bt

我唯一的问题是两个:

  1. 当您单击Add按钮时,默认的WooCommerce AJAX调用似乎会受到干扰,就像页面被smoothState.js操作所干扰一样。我想知道如何在“添加到购物车”按钮上禁用smoothState.js。
  2. 例如,当您单击注销和注销时,尝试重新登录或注册只运行smoothState.js,而不将这些其他链接重定向到相应的操作。所以,在这些登录和注册链接上,我想禁用smoothState.js。

能不能找个更能胜任这个助手的人?

顺便提一下,这是我用来调用smoothState.js的代码。我从Envato在这个链接https://webdesign.tutsplus.com/tutorials/how-to-integrate-smoothstatejs-into-a-wordpress-theme--cms-26610上的图斯普鲁斯教程中获得了这段代码。

代码语言:javascript
复制
// Using smoothstate-js to Ajax-load pages
(function($) {
  function addBlacklistClass() {
    $('a').each( function() {
      if (this.href.indexOf('/wp-admin/') !== -1 ||
        this.href.indexOf('/wp-login.php') !== -1) {
        $(this).addClass('wp-link');
      }
    });
  }

  $(function() {
    addBlacklistClass();

    var settings = {
      anchors: 'a',
      blacklist: '.wp-link',
      onStart: {
        duration: 320,
        render: function ($container) {
          $container.addClass('slide-out');
        }
      },
      onAfter: function($container) {
        addBlacklistClass();

        var $hash = $(window.location.hash);
        if ($hash.length !== 0) {
          var offsetTop = $hash.offset().top;

          $('body, html').animate({
              scrollTop: (offsetTop - 60),
            }, {
              duration: 320
          } );
        }

        $container.removeClass('slide-out');
      }
    };

    $('#app').smoothState(settings);
  });
})(jQuery); // End smoothstate-js

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-01-15 18:04:45

我给黑名单函数增加了几行代码,这似乎解决了这个问题。不过,我会继续调查,以确保一切正常。现在,除了你想破坏我的密码,我觉得我很好。

代码语言:javascript
复制
(function($) {
  function addBlacklistClass() {
    $('a').each( function() {
      if (this.href.indexOf('/wp-admin/') !== -1 ||
      this.href.indexOf('/wp-login.php') !== -1 ||
      this.href.indexOf('/?add-to-cart') !== -1 ||
      this.href.indexOf('?remove_item') !== -1) {
        $(this).addClass('no-smoothState');
      }
    });

    $('input[type="submit"]').each(function() {
      $(this).addClass('no-smoothState');
    });
  }

  $(function() {
    addBlacklistClass();

    var settings = {
      anchors: 'a',
      forms: 'input',
      blacklist: '.no-smoothState',
      onStart: {
        duration: 320,
        render: function ($container) {
          $container.addClass('slide-out');
        }
      },
      onAfter: function($container) {
        addBlacklistClass();

        var $hash = $(window.location.hash);
        if ($hash.length !== 0) {
          var offsetTop = $hash.offset().top;

          $('body, html').animate({
              scrollTop: (offsetTop - 60),
            }, {
              duration: 320
          } );
        }

        $container.removeClass('slide-out');
      }
    };

    $('#app').smoothState(settings);
  });
})(jQuery);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41649310

复制
相关文章

相似问题

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