繁体   English   中英

该功能在台式机和仿真器上有效,但不适用于移动浏览器

[英]Function works on desktop and emulator but not on mobile browsers

我有一个WordPress Woocomerce网站。 我具有更多/更少阅读功能,可以扩展/隐藏较长的产品说明。 它在桌面上运行良好。 它甚至可以使用Chrome的移动仿真器工具运行。

但是,它不适用于任何移动浏览器。 按下按钮只会使页面跳上一点。 我假设浏览器没有读取.on('click 'touchstart').

$(document).ready(function() {

      $(".product-readmore").on('click touchstart', function() {

          var description = document.querySelector(".product-description-readmore");

          if (description.style.height === '') {
            description.style.height = 'auto';
          } else if (description.style.height === 'auto') {
            description.style.height = '';
          } else {
            description.style.height = '92px';
          }

          $(this).text($(this).text() == 'Read less...' ? 'Read more...' : 'Read 
            less...');
          });
      });

事实证明,问题在于WordPress如何处理jQuery。 我将第一行更改为jQuery(document).ready(function($){

现在,它可以在所有浏览器(移动版和其他版本)上正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM