//事件兼容 var xxevents = ('ontouchstart' in window) ? { start: 'touchstart', move: 'touchmove', end: 'touchend' } : { start: 'click', move: 'mousemove', end: 'mouseup' }; $(function() { var indexnav = $('.page-list .active').index(); $('.page-list li').hover( function() { $(this).addclass('active').siblings().removeclass('active'); }, function() { $(this).removeclass('active'); $('.page-list li').eq(indexnav).addclass('active'); } ); }); //返回角度 function getslideangle(dx, dy) { return math.atan2(dy, dx) * 180 / math.pi; } //根据起点和终点返回方向 1:向上,2:向下,3:向左,4:向右,0:未滑动 function getslidedirection(startx, starty, endx, endy) { var dy = starty - endy; var dx = endx - startx; var result = 0; //如果滑动距离太短 if (math.abs(dx) < 10 && math.abs(dy) < 10) { return result; } var angle = getslideangle(dx, dy); if (angle >= -45 && angle < 45) { result = 4; } else if (angle >= 45 && angle < 135) { result = 1; } else if (angle >= -135 && angle < -45) { result = 2; } else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) { result = 3; } return result; } //滑动处理 function touchscroll(obj,fn){ var startx, starty; obj.addeventlistener('touchstart', function (e) { startx = event.touches[0].pagex; starty = event.touches[0].pagey; }, false); obj.addeventlistener('touchmove', function (e) { var endx, endy; endx = event.changedtouches[0].pagex; endy = event.changedtouches[0].pagey; var direction = getslidedirection(startx, starty, endx, endy); var movex=endx-startx; switch (direction) { case 0: //alert("没滑动"); break; case 1: //alert("向上"); break; case 2: //alert("向下"); break; case 3: //alert("向左"); if(fn.leftmove) fn.leftmove(movex); event.preventdefault(); break; case 4: //alert("向右"); if(fn.rightmove) fn.rightmove(movex); event.preventdefault(); break; default: } }, false); obj.addeventlistener('touchend', function (e) { var endx, endy; endx = event.changedtouches[0].pagex; endy = event.changedtouches[0].pagey; var direction = getslidedirection(startx, starty, endx, endy); switch (direction) { case 0: if(fn.notouch) fn.notouch(); break; case 1: //alert("向上"); break; case 2: //alert("向下"); break; case 3: //alert("向左"); if(fn.leftend) fn.leftend(); event.preventdefault(); break; case 4: //alert("向右"); if(fn.rightend) fn.rightend(); event.preventdefault(); break; default: } }, false); } /*自定义插件*/ jquery.fn.extend({ zpimgmove: function () { this.each(function (index, docele) { var box = $('.zp_imgchange', docele); var abigli = $('.js_move li', docele); var smallbox = $('.zps_disarea ul', docele); var asmallli = $('.zps_disarea li', docele); var prev = $('.zps_prev', docele); var next = $('.zps_next', docele); var bul = $('.js_btn', docele); var bigimg = abigli.eq(0).find('img:first')[0]; var inow = 0, ilast = 0, fx = 1, bx = 710, by = 0, logic = true, html, snow = 0, num = 4, sy = 72; var _length = asmallli.length; var xnum = _length - num; var popupbtn = $('.zp_fancybox', docele); //添加小点 if (bul != null || bul != undefined) { for (var i = 0; i < _length; i++) { if (html) html += '
'; else html = ''; } bul.html(html); } var bli = $('.js_btn li', docele); asmallli.eq(inow).addclass('current'); bli.eq(inow).addclass('current'); abigli.eq(inow).css('left', 0); popupbtn.attr('href', abigli.eq(inow).attr('bigimg')); prev.hide(); if (xnum <= 0) { prev.hide(); next.hide(); } else { prev.click(function () { snow--; move1(); }); next.click(function () { snow++; move1(); }); } asmallli.click(function () { if (logic) { ilast = inow; inow = $(this).index(); move2(); } }); bul.delegate('li', 'click', function () { if (logic) { ilast = inow; inow = $(this).index(); move2(); } }); touchscroll(box[0], { leftend: function () { ilast = inow; inow++; move2(); }, rightend: function () { ilast = inow; inow--; move2(); } }); function move1() { prev.show(); next.show(); if (snow <= 0) { snow = 0; prev.hide(); } if (snow >= xnum) { snow = xnum; next.hide(); } smallbox.stop().animate({ top: -snow * sy }, 'slow'); } function move2() { if (inow == ilast) return; logic = false; if (inow < ilast) fx = -1; else fx = 1; $('.estate-list .estate-content').eq(inow).addclass('on').siblings().removeclass('on'); abigli.eq(inow).css('left', fx * bx); abigli.eq(inow).stop().animate({ left: 0 }, 'slow', function () { logic = true; }); abigli.eq(ilast).stop().animate({ left: -bx * fx }, 'slow'); asmallli.removeclass('current'); asmallli.eq(inow).addclass('current'); bli.removeclass('current'); bli.eq(inow).addclass('current'); popupbtn.attr('href', abigli.eq(inow).attr('bigimg')); fx = 1; } function autoinit() { bx = bigimg.width; by = bigimg.height; abigli.stop().css('left', '100%'); abigli.eq(inow).css('left', 0); logic = true; box.height(by); } autoinit(); $(window).resize(autoinit); }); } }); $('.page-progress-bar .control-bar').click(xxevents.move,function (g) { var tabs = $(this), index = $(this).index(), tabcons = $('.bd .piclist'); $('#page-progress-bar li').removeclass('on'); tabs.addclass('on'); tabcons.not(tabcons.eq(index)).hide(); tabcons.eq(index).show(); g.preventdefault(); }); $('.year a').click(xxevents.move,function (g) { var tabs = $(this), index=$(this).index(); tabcons = $('.year-cont .year-ul'); $('.year a').removeclass('yearter'); tabs.addclass('yearter'); tabcons.not(tabcons.eq(index)).hide(); tabcons.eq(index).show(); g.preventdefault(); }); $('.box-nav a').click(xxevents.move,function (g) { var tabs = $(this), index = $(this).index(), tabcons = $('.year-cont .year-ul'); $('.box-nav a').removeclass('avte'); tabs.addclass('avte'); tabcons.not(tabcons.eq(index)).hide(); tabcons.eq(index).show(); g.preventdefault(); }); //移动端检测 function is_mobile() { return navigator.useragent.tolowercase().match(/(iphone|ipod|ipad|android|blackberry|bb10|mobi|tablet|opera mini|nexus 7)/i) ? true : false; } var _xx = _xx || {}; //_xx命名空间 var wrap = $('.wrapper:first'), btn = $('#js-touch-menu-btn'), box = $('#touch-nav-list'); //移动导航 _xx.touchnav = function () { btn.on(xxevents.start, function (e) { e.preventdefault(); if ($(this).hasclass('touch-menu-button-on')) { $(this).removeclass('touch-menu-button-on'); box.removeclass('touch-nav-body-on'); wrap.removeclass('wrapper-on'); } else { $(this).addclass('touch-menu-button-on'); box.addclass('touch-nav-body-on'); wrap.addclass('wrapper-on'); } }); }; //移动端二级菜单导航 _xx.curmbnav = function () { var curmbmenu = $('.main-menu'), curmbbtn = $('.main-menu-btn'); curmbbtn.on('click', function (e) { e.preventdefault(); if ($(this).hasclass('main-menu-on')) { $(this).removeclass('main-menu-on'); curmbmenu.slideup(200); } else { $(this).addclass('main-menu-on'); curmbmenu.slidedown(200); } }); }; function shareto(stype){ var ftit = ''; var flink = ''; var lk = ''; //获取文章标题 ftit = $('.news-details-con-title').text(); //获取网页中内容的第一张图片 flink = $('.news-details img').eq(0).attr('src'); if(typeof flink == 'undefined'){ flink=''; } //当内容中没有图片时,设置分享图片为网站logo if(flink == ''){ lk = 'http://'+window.location.host+'/static/images/logo.png'; } //如果是上传的图片则进行绝对路径拼接 if(flink.indexof('/uploads/') != -1) { lk = 'http://'+window.location.host+flink; } //百度编辑器自带图片获取 if(flink.indexof('ueditor') != -1){ lk = flink; } //qq空间接口的传参 if(stype=='qzone'){ window.open('https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url='+document.location.href+'?sharesource=qzone&title='+ftit+'&pics='+lk+'&summary='+document.queryselector('meta[name="description"]').getattribute('content')); } //新浪微博接口的传参 if(stype=='sina'){ window.open('http://service.weibo.com/share/share.php?url='+document.location.href+'?sharesource=weibo&title='+ftit+'&pic='+lk+'&appkey=2706825840'); } //qq好友接口的传参 if(stype == 'qq'){ window.open('http://connect.qq.com/widget/shareqq/index.html?url='+document.location.href+'?sharesource=qzone&title='+ftit+'&pics='+lk+'&summary='+document.queryselector('meta[name="description"]').getattribute('content')); } //生成二维码给微信扫描分享,php生成,也可以用jquery.qrcode.js插件实现二维码生成 if(stype == 'wechat'){ window.open('http://zixuephp.net/inc/qrcode_img.php?url=http://zixuephp.net/article-1.html'); } } function dateftt(fmt, date) { //author: meizz var o = { "m+": date.getmonth() + 1, //月份 "d+": date.getdate(), //日 "h+": date.gethours(), //小时 "m+": date.getminutes(), //分 "s+": date.getseconds(), //秒 "q+": math.floor((date.getmonth() + 3) / 3), //季度 "s": date.getmilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(regexp.$1, (date.getfullyear() + "").substr(4 - regexp.$1.length)); for (var k in o) if (new regexp("(" + k + ")").test(fmt)) fmt = fmt.replace(regexp.$1, (regexp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }