Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //小轮播==================
- //获取接口json数据
- function loadData(_url,data,fn){
- var url = _url+"?"+data+"&callback="+fn;
- var t=document.createElement("script");
- t.src=url,t.type="text/javascript",t.async=!0;
- document.getElementsByTagName("head")[0].appendChild(t);
- t.onload=function(){document.getElementsByTagName("head")[0].removeChild(t);}
- }
- //获取接口json数据
- // banner事件
- loadData('http://api.act.sdo.com/UnionNews/List','gameCode=ma&category=7161&pageIndex=0&pageSize=10','handleBannerData');
- function handleBannerData(data){
- //console.log(JSON.stringify(data));
- if(data.Code=='0'&&data.TotalCount>0){
- var html='';
- for(var i=0;i<data.TotalCount;i++){
- if(i==0){
- html+='<li class="dis">';
- }else{
- html+='<li class="">';
- }
- if(data.Data[i].OutLink) {
- html+='<a href="'+data.Data[i].OutLink+'" target="_blank"><img src="'+data.Data[i].HomeImagePath+'"></a></li>';
- }else {
- html+='<img src="'+data.Data[i].HomeImagePath+'"></li>';
- }
- }
- $("#lundiv").html(html);
- bannerScroll();
- }
- }
- // banner事件
- function bannerScroll(){
- // 定义一个信号量
- var num = 0;
- var len=$("#lundiv li").length;
- var timer = null;
- if (len == 1){
- $('#lunsrol').html('');
- } else {
- for(i=0;i<len;i++){
- $("<li></li>").appendTo("#lunsrol");
- }
- }
- $("#lunsrol li:first").addClass("on");
- // 1 实现下方小li鼠标移上相应动画
- $('.lunsrol li').mouseover(function(){
- var index = $(this).index();
- num = index;
- $(this).addClass('on').siblings().removeClass('on');
- // 下面是我们实现交叉淡入的一个原理
- $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
- });
- // 点击事件
- $('.left').click(function(){
- // 看下当前li是否正在做动画。
- if( !$('.lundiv li').is(":animated") ){
- num--;
- if( num == -1 ){
- num = len-1;
- }
- $('.lunsrol li').eq(num).addClass('on').siblings().removeClass('on');
- // 下面是我们实现交叉淡入的一个原理
- $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
- }
- });
- $('.right').click(function(){
- // 看下当前li是否正在做动画。
- if( !$('.lundiv li').is(":animated") ){
- num++;
- if( num == len ){
- num = 0;
- }
- $('.lunsrol li').eq(num).addClass('on').siblings().removeClass('on');
- // 下面是我们实现交叉淡入的一个原理
- $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
- }
- });
- // 开启定时器
- timer = setInterval( autoplay,2000 );
- // 封装动画
- function autoplay(){
- if( !$('.lundiv li').is(":animated") ){
- num++;
- if( num == len){
- num = 0;
- }
- $('.lunsrol li').eq(num).addClass('on').siblings().removeClass('on');
- // 下面是我们实现交叉淡入的一个原理
- $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
- }
- }
- $('.banner').mouseover(function(){
- clearInterval( timer );
- // $('.lunBtn').show();
- }).mouseout(function(){
- timer = setInterval( autoplay,2000 );
- // $('.lunBtn').hide();
- });
- lent();
- }
- //定位轮播下标的位置
- function lent(){
- var numX= $("#lunsrol li").length;
- var lent=-($("#lunsrol li").width()+8);
- $('#lunsrol').css({'margin-left':lent})
- }
- $('.mask').height($('body,html').height());
- //登陆选择角色
- $('.close_btn').click(function () {
- $(this).parent().hide();
- $('.mask').hide();
- });
- function isRoleName() {
- var isrol = false;
- if($('#LoginRoleName').html()){
- isrol = true;
- }else {
- isrol = false;
- }
- return isrol;
- }
- var ajaxUrl = "./Server/Item.ashx";
- var pageAct = 1;
- var Cookie = {
- set: function(key, val, expiresDays){//这里传天数
- //判断是否设置expiresDays
- if (expiresDays){
- //说明要保存Cookie有效期
- var date = new Date();
- date.setTime(date.getTime()+expiresDays*1*3600*1000);//这里是微秒,格式化时间
- var expiresStr = "expires=" + date.toGMTString() + ';' ;
- } else {
- var expiresStr = '';
- }
- //拼接Cookie,注意大小写
- document.cookie = key+'='+escape(val)+';' + expiresStr;//escape()字符串进行编码
- },
- get: function(key){
- //Cookie存储格式:"key1=val1; key2=val2; key3=val3"
- var getCookie = document.cookie.replace(/[ ]/g,'');//把[ ] 换成 ''
- //通过';'分割成数组
- var resArr = getCookie.split(';');
- var res;
- for (var i = 0; i < resArr.length; i++) {
- var arr = resArr[i].split('=');
- //判断传入key是否找到存储对应的val
- if (arr[0] == key){
- res = arr[1];
- break;
- }
- }
- return unescape(res);//解码
- }
- }
- var cookNum = Cookie.get('ffPageNum');
- if(!!cookNum&&cookNum!=='undefined'){
- itemlistFun(cookNum);
- } else {
- itemlistFun(1);
- Cookie.set('ffPageNum',1,1);
- }
- var initFlag = true;
- function itemlistFun(num) {
- var dataPrams = "method=itemlist";
- dataPrams = dataPrams + "&pageNum=" + num;
- dataPrams = dataPrams + "&i=" + Math.random();
- $.ajax({
- type: "post",
- dataType: "json",
- url: ajaxUrl,
- data: dataPrams,
- success: function (data) {
- if (data.Code == 0) {
- // console.log(data);
- if (initFlag) {
- $('.M-box4').pagination({
- pageCount: data.Attach.PageCount,
- coping: true,
- current:num,
- homePage: '首页',
- endPage: '末页',
- prevContent: '上页',
- nextContent: '下页',
- callback: function (api) {
- // console.log('测试当前=' + api.getCurrent())
- itemlistFun(api.getCurrent())
- Cookie.set('ffPageNum',api.getCurrent(),1);
- }
- });
- initFlag = false;
- }
- $("#shoplist").html("");
- creatLiFun(data.Attach.ItemList);
- } else {
- // alert(data.Message);
- }
- }
- });
- }
- function getCurrentDate(format) {
- var now = new Date();
- var year = now.getFullYear(); //得到年份
- var month = now.getMonth();//得到月份
- var date = now.getDate();//得到日期
- var day = now.getDay();//得到周几
- var hour = now.getHours();//得到小时
- var minu = now.getMinutes();//得到分钟
- var sec = now.getSeconds();//得到秒
- month = month + 1;
- if (month < 10) month = "0" + month;
- if (date < 10) date = "0" + date;
- if (hour < 10) hour = "0" + hour;
- if (minu < 10) minu = "0" + minu;
- if (sec < 10) sec = "0" + sec;
- var time = ""; //精确到天
- if(format==1){ time = year + "-" + month + "-" + date; } //精确到分
- else if(format==2){
- time = year + "/" + month + "/" + date+ " " + hour + ":" + minu + ":" + sec;
- }
- return time;
- }
- // 对Date的扩展,将 Date 转化为指定格式的String
- // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
- // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
- // 例子:
- // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
- // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
- Date.prototype.Format = function (fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt))
- fmt = fmt.replace(RegExp.$1, (this.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;
- }
- // var time1 = listdata[i].CreateTime;
- // var time2 = time1.replace("/Date(", "").replace(")/", ""); //先替换掉 /date( )/
- // time2 = time2.split('+')[0];
- // var newDate = new Date(); //转成date类型
- // newDate.setTime(time2); //这步很关键
- // newDate.Format("yyyy-MM-dd hh:mm:ss")
- function creatLiFun(ret) {
- var listHtml = '';
- for (var i = 0; i < ret.length; i++) {
- var ntimes = getCurrentDate(2);
- var myDate = new Date(ntimes).getTime();
- var timeSta = ret[i].StartTime1.replace("/Date(", "").replace(")/", "");
- var timeSta2 = ret[i].StartTime2.replace("/Date(", "").replace(")/", "");
- var timeEnd = ret[i].EndTime1.replace("/Date(", "").replace(")/", "");
- var timeEnd2 = ret[i].EndTime2.replace("/Date(", "").replace(")/", "");
- // var ttimexxx = ret[i].StartTime1.replace("/Date(", "").replace(")/", "");
- // console.log(ttimexxx)
- // console.log(myDate)
- listHtml += '<div class="sitem">';
- if(ret[i].Type == 3) {
- //普通商品
- listHtml += '<a href="productp.html?itemid='+ ret[i].Id +'">';
- if(myDate > timeEnd) {
- listHtml += '<div class="tit titp titover">暂无货</div>';
- } else if (myDate < timeSta) {
- listHtml += '<div class="tit titp titover">敬请期待</div>';
- } else {
- listHtml += '<div class="tit titp">普通商品</div>';
- }
- }
- if(ret[i].Type == 2) {
- // 抽选商品
- // if (myDate < timeSta) {
- // listHtml += '<a href="javascript:;">';
- // } else {
- // listHtml += '<a href="productc.html?itemid='+ ret[i].Id +'">';
- // }
- listHtml += '<a href="productc.html?itemid='+ ret[i].Id +'">';
- if(myDate > timeEnd2) {
- listHtml += '<div class="tit titc titover">暂无货</div>';
- }
- if (myDate > timeEnd && myDate < timeSta2) {
- listHtml += '<div class="tit titc titover">抽选结束</div>';
- }
- if (myDate > timeSta && myDate < timeEnd) {
- listHtml += '<div class="tit titc">抽选商品</div>';
- }
- if (myDate < timeSta) {
- listHtml += '<div class="tit titc titover">敬请期待</div>';
- }
- }
- if(ret[i].Type == 1) {
- // 预定商品
- // if (myDate < timeSta) {
- // listHtml += '<a href="javascript:;">';
- // } else {
- // listHtml += '<a href="product.html?itemid='+ ret[i].Id +'">';
- // }
- listHtml += '<a href="product.html?itemid='+ ret[i].Id +'">';
- if(myDate > timeEnd2) {
- listHtml += '<div class="tit tity titover">暂无货</div>';
- }
- if (myDate > timeEnd && myDate < timeSta2) {
- listHtml += '<div class="tit tity titover">预售结束</div>';
- }
- if(myDate > timeSta2 && myDate <timeEnd2) {
- listHtml += '<div class="tit tity titstart">补款开启</div>';
- }
- if (myDate > timeSta && myDate < timeEnd) {
- listHtml += '<div class="tit tity">预售商品</div>';
- }
- if (myDate < timeSta) {
- listHtml += '<div class="tit tity titover">敬请期待</div>';
- }
- // listHtml += '<div class="tit tity"></div>';
- }
- // if (myDate < timeSta) {
- // listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
- // listHtml += '<div class="name">敬请期待</div>';
- // } else {
- // listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
- // listHtml += '<div class="name">'+ret[i].ItemName+'</div>';
- // }
- listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
- listHtml += '<div class="name">'+ret[i].ItemName+'</div>';
- // listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
- // listHtml += '<div class="name">'+ret[i].ItemName+'</div>';
- listHtml += '</a>';
- listHtml += '</div>';
- }
- // for (var i = listdata.length-1; i >= 0; i--) {}
- $("#shoplist").html(listHtml);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement