js菜雞-------自我記錄javascript
html頁面:css
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> <meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="address=no"> <title>iscroll-測試</title> <link href="css/reset.css" rel="stylesheet" type="text/css"> <link href="css/cm.css" rel="stylesheet" type="text/css"> </head> <style> span{display:block;width:100%;text-align:center;} </style> <body> <div id="wrapper"> <div id="scroller"> <div id="pullDown"> <span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新</span> </div> <!--信息列表--> <ul id="thelist"> <div class="cm-v2 no-border"> <section class="doc-box"> <ul class="doctorUlList" id="doctorUlListAuto"> <!--此處展現具體信息 --> </ul> </section> </div> </ul> <div id="pullUp"> <span class="pullUpIcon"></span><span class="pullUpLabel" >查看更多</span> </div> </div> </div> <div id="footer"></div> <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="js/iscroll.js"></script> <script type="text/javascript" src="js/getList-iscroll.js"></script> <script type="text/javascript"> var currentPage = 1; Ajax(currentPage); var myScroll, pullDownEl, pullDownOffset, pullUpEl, pullUpOffset; function loaded() { pullDownEl = document.getElementById('pullDown'); pullDownOffset = pullDownEl.offsetHeight; pullUpEl = document.getElementById('pullUp'); pullUpOffset = pullUpEl.offsetHeight; myScroll = new iScroll('wrapper', { useTransition: true, topOffset: pullDownOffset, onRefresh: function () { if (pullDownEl.className.match('loading')) { pullDownEl.className = ''; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'refresh...'; } else if (pullUpEl.className.match('loading')) { pullUpEl.className = ''; pullUpEl.querySelector('.pullUpLabel').innerHTML = 'load more...'; } }, onScrollMove: function () { if (this.y > 5 && !pullDownEl.className.match('flip')) { pullDownEl.className = 'flip'; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'refresh...'; this.minScrollY = 0; } else if (this.y < 5 && pullDownEl.className.match('flip')) { pullDownEl.className = ''; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'refresh...'; this.minScrollY = -pullDownOffset; } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) { pullUpEl.className = 'flip'; pullUpEl.querySelector('.pullUpLabel').innerHTML = 'refresh...'; this.maxScrollY = this.maxScrollY; } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) { pullUpEl.className = ''; pullUpEl.querySelector('.pullUpLabel').innerHTML = 'load more...'; this.maxScrollY = pullUpOffset; } }, onScrollEnd: function () { if (pullDownEl.className.match('flip')) { pullDownEl.className = 'loading'; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...'; pullDownAction(); } else if (pullUpEl.className.match('flip')) { pullUpEl.className = 'loading'; pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...'; pullUpAction(); } } }); setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 800); } function pullDownAction () { window.location.reload(); } function pullUpAction () { var page = currentPage++; Ajax(page); myScroll.refresh(); } document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false); </script> </body> </html>
ajax請求後臺數據:html
/** * Created by jstarseven on 2016/3/7. */ function Ajax(page) { $.ajax({ type: "post", dataType: "JSON", url: "http://xx.xxxxxx.com/wx_service/getList", data: {'page': page}, success: function (data) { var item = ''; $.each(data, function (i, result) { var skill = result['skill']; item += '<li>'; item += '<a href="getDoctorDetail.html?doctorId=' + result['doctorId'] + '">'; item += '<div class="doc-pic"><img id="headPicUrl" src="' + result['headPicUrl'] + '" alt=""></div>'; item += '<div class="doc-info">'; item += '<h4><span>' + result['doctorName'] + '</span> <span>' + result['doctorTitle'] + '</span></h4>'; item += '<p class="c-666">' + result['hospitalName'] + '</p>'; item += '<p class="shanchang" id="skillBegin">'; $.each(skill, function (i) { item += '<span>' + skill[i] + '</span>'; }) item += '</p>'; item += '<div class="feiyong">'; item += '<span class="s1">¥ <span>' + result['consultPrice'] + '</span>/次</span>'; item += '<span class="s2"><span>' + result['payNumber'] + '</span>人付款,<span>' + result['praisePercent'] + '</span> 好評</span>'; item += '</div>'; item += '</div>'; item += '</a>'; item += '</li>'; }); $('.doctorUlList').append(item); }, error: function () { console.log("當前請求失敗"); } }); }
-END-java