<div id="tab3" class="weui-tab__bd-item"> <!----搜索框---> <div class="weui-search-bar weui-search-bar_focusing" id="searchBar"> <form class="weui-search-bar__form"> <div class="weui-search-bar__box"> <i class="weui-icon-search"></i> <input type="search" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required=""> <a href="javascript:" class="weui-icon-clear" id="searchClear"></a> </div> <label class="weui-search-bar__label" id="searchText"> <i class="weui-icon-search"></i> <span>搜索</span> </label> </form> <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a> </div>根据代码,用jquey写下拉刷新效果
时间: 2024-02-15 13:01:59 浏览: 142
下面是使用 jQuery 实现下拉刷新的代码示例:
HTML 结构:
```html
<div id="tab3" class="weui-tab__bd-item">
<!-- 搜索框 -->
<div class="weui-search-bar weui-search-bar_focusing" id="searchBar">
<form class="weui-search-bar__form">
<div class="weui-search-bar__box">
<i class="weui-icon-search"></i>
<input type="search" class="weui-search-bar__input" id="searchInput" placeholder="搜索" required="">
<a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
</div>
<label class="weui-search-bar__label" id="searchText">
<i class="weui-icon-search"></i>
<span>搜索</span>
</label>
</form>
<a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
</div>
<!-- 下拉刷新 -->
<div class="pull-to-refresh-content">
<div class="pull-to-refresh-layer">
<div class="preloader"></div>
<div class="pull-to-refresh-arrow"></div>
</div>
<!-- 列表内容 -->
<ul class="list"></ul>
</div>
</div>
```
CSS 样式:
```css
/* 下拉刷新 */
.pull-to-refresh-content {
position: relative;
overflow: auto;
}
.pull-to-refresh-layer {
position: absolute;
top: -40px;
width: 100%;
height: 40px;
text-align: center;
line-height: 40px;
color: #999;
font-size: 14px;
}
.pull-to-refresh-arrow {
display: inline-block;
vertical-align: middle;
margin-right: 10px;
width: 10px;
height: 10px;
border: 1px solid #999;
border-top: none;
border-right: none;
transform: rotate(-45deg);
}
.pull-to-refresh-layer .preloader {
display: inline-block;
vertical-align: middle;
margin-right: 10px;
}
/* 列表 */
.list {
margin: 0;
padding: 0;
list-style: none;
}
.list li {
padding: 10px;
border-bottom: 1px solid #ccc;
}
```
JavaScript 代码:
```javascript
$(function() {
// 获取下拉刷新区域和列表区域
var $ptrContent = $('.pull-to-refresh-content');
var $list = $('.list');
// 初始化下拉刷新
$ptrContent.on('ptr:refresh', function(e) {
// 模拟 AJAX 请求
setTimeout(function() {
// 生成新的列表项
var newItem = '<li>新的列表项</li>';
// 将新的列表项插入到列表中
$list.prepend(newItem);
// 结束下拉刷新
$.pullToRefreshDone($ptrContent);
}, 2000);
});
// 初始化下拉刷新插件
$ptrContent.ptr({
// 修改默认的下拉刷新文字
pullText: '下拉刷新',
releaseText: '释放刷新',
refreshText: '正在刷新...',
// 修改默认的下拉刷新图标
iconArrow: '<div class="pull-to-refresh-arrow"></div>',
iconRefreshing: '<div class="preloader"></div>',
// 修改默认的下拉刷新触发距离
distance: 50
});
});
```
注意:上面的代码使用了第三方的下拉刷新插件 `pull-to-refresh-js`,需要先引入该插件。
阅读全文