$(function () { //header $('#menu-btn').on('click', function () { $('.app-header').toggleClass('open'); }); // nav click $('.child-link').on('click', function () { $(this).parent('.menu-item').toggleClass('on'); $(this).siblings('.child').slideToggle(); return false; }); // footer $('.app-footer .link-name').on('click', function () { $(this).parent().siblings().find('.link-list').slideUp(); $(this).siblings('.link-list').stop().slideToggle(); $(this).parent().toggleClass('on').siblings().removeClass('on'); }); /** * 返回顶部 */ $('#go-top').on('click', function () { $('html,body').animate({ 'scrollTop': 0 }); }); $(window).on('scroll', function () { var winH = $(window).height(); var top = $(document).scrollTop(); if (top >= winH * 1.5) { $('#go-top').stop().fadeIn(200); } else { $('#go-top').stop().fadeOut(200); } }) /*****************/ $('.weixin-share-box').on('click', function () { var $that = $(this); $(this).toggleClass('on'); if ($(this).hasClass('on')) { setTimeout(function () { $(document).one('click', function () { $that.removeClass('on'); }); }) } }); }); //分享到新浪微博 function shareToSinaWB(event) { event.preventDefault(); var _shareUrl = 'http://v.t.sina.com.cn/share/share.php?'; //真实的appkey,必选参数 _shareUrl += '&url=' + encodeURIComponent(shareConfig._url || document.location); //参数url设置分享的内容链接|默认当前页location,可选参数 _shareUrl += '&title=' + encodeURIComponent(shareConfig._title || document.title); //参数title设置分享的标题|默认当前页标题,可选参数 _shareUrl += '&source=' + encodeURIComponent(shareConfig._source || ''); _shareUrl += '&sourceUrl=' + encodeURIComponent(shareConfig._sourceUrl || ''); _shareUrl += '&content=' + 'utf-8'; //参数content设置页面编码gb2312|utf-8,可选参数 _shareUrl += '&pic=' + encodeURIComponent(shareConfig._pic || ''); //参数pic设置图片链接|默认为空,可选参数 window.open(_shareUrl, '_blank'); } //分享到QQ空间 function shareToQzone(event) { event.preventDefault(); var _shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?'; _shareUrl += 'url=' + encodeURIComponent(shareConfig._url || document.location); //参数url设置分享的内容链接|默认当前页location _shareUrl += '&desc=' + encodeURIComponent(shareConfig._desc || '分享的描述'); //参数desc设置分享的描述,可选参数 _shareUrl += '&summary=' + encodeURIComponent(shareConfig._summary || '分享摘要'); //参数summary设置分享摘要,可选参数 _shareUrl += '&title=' + encodeURIComponent(shareConfig._title || document.title); //参数title设置分享标题,可选参数 _shareUrl += '&site=' + encodeURIComponent(shareConfig._site || ''); //参数site设置分享来源,可选参数 _shareUrl += '&pics=' + encodeURIComponent(shareConfig._pic || ''); //参数pics设置分享图片的路径,多张图片以"|"隔开,可选参数 window.open(_shareUrl, '_blank'); } //请求数据 function loadMore(config, closeList) { var sendData = { pageIndex: config.pageIndex, pageSize: config.pageSize }; $.extend(sendData, config.qry); $.get(config.url, sendData, function result(res) { if (!res) { alert('请求出错' + res.message); return; } var data = res; if (typeof config.pipe === 'function') { config.pipe(data); } var html = ''; data.forEach(function (v, i) { html += $('#template').html().replace(/{{([^{}]+?)}}/igm, function (match, key) { return v[key]; }); }); if (closeList === true) { config.list.html(''); } config.list.append($(html)); if (typeof config.afterFun === 'function') { config.pipe(data); } //判断是否还有数据 if (data.length < config.pageSize) { $('.empty-text').html(''); $(document).off('scroll.more'); } else { $('.empty-text').html('↑上划加载更多...'); } config.onOff = true; }); } //上滑刷新 function scrollData(config) { $(document).off('scroll.more'); if ($('.empty-text').attr('empty') !== 'true') { $(document).on('scroll.more', function () { var vTop = $(document).scrollTop(); var bottom = $('.empty-text').offset().top - 100; //多减100px 提前加载 if (vTop >= bottom - innerHeight && config.onOff) { config.onOff = false; $('.empty-text').html('加载中. . .'); //准备请求 config.pageIndex++; loadMore(config); } }) } }