首页 > 解决方案 > 我的 jQuery (touchstart) 不能在 iPhone 上运行

问题描述

我使用了一个 jQuery 函数来折叠 div 标签的内容。不幸的是,这个功能似乎不适用于 iPhone。请帮助我使它工作,谢谢!

我的网站:https ://thuexedulich.danang.vn/thue-xe-da-nang/

let touchEvent = 'ontouchstart' in window ? 'touchstart' : 'click';

$('.expand-button').on(touchEvent, function(){
  $('.cat-decs').toggleClass('-expanded');
  if ($('.cat-decs').hasClass('-expanded')) {
    $('.expand-button').html('Click to Hide');
  } else {
    $('.expand-button').html('Click to Read More');
  }
});
.cat-decs {border-top: 3px solid var(--main-color)}
.expand-button {
    cursor: pointer;
    display: block;
    width: 30%;
    text-align: center;
    margin-top: 1rem;
    margin-left: auto;
    margin-right: auto;
    color: var(--main-color)!important
}
/*.expand-button:hover {color: #fff!important}*/
.cat-decs{
  position: relative;
  max-height: 200px;
  overflow: hidden;
  transition: max-height .3s ease;
}
.cat-decs.-expanded {
  max-height: 100%;
}
.cat-decs:not(.-expanded)::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="entry-content cat-decs">
  <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
  <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
  <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
  <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
  <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
<a class="expand-button btn btn-more">Click to Read More</a>

标签: javascriptjqueryhtmlcss

解决方案


推荐阅读