javascript - 我的 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>
解决方案
推荐阅读
- karate - 在空手道中尝试定义一个变量时得到“没有找到匹配的步骤定义方法:def referenceId = response.referenceId”
- python - 插入具有重复记录列的表中(有问题的屏幕)
- python - 在 Python 代码中获取 AttributeError(同时从父类继承) - 面向对象编程的作业 30 (INFYTQ)
- python - 使用 simple-salesforce 从 salesforce 表中删除表行
- hyperledger-fabric - 如何将另一个组织和用户添加到该组织?
- java - 在 JavaFX 应用程序之上显示 AnchorPane
- java - 如何修复除法以获得正确的输出?
- jquery - Rails 使用 AJAX 参数从视图发送到控制器中的自定义操作
- python - 替换python df问题中的字符串
- python - lmdb.BadRslotError:mdb_txn_begin:MDB_BAD_RSLOT:读取器锁表插槽的重复使用无效?