// api列表 var api = { baseurl: 'https://admin.sangoods.com/api/', // api地址 gethomelist: 'home/gethomelist', // 首页 getproductlist: 'product/getproductlist', //产品列表 getcasuslist: 'casus/getcasuslist', //客户案例 getdownloadlist: 'download/getdownloadlist', // 下载列表 getproductinfo: 'product/getproductinfo', //产品详情 getnewslist: 'news/getnewslist', //新闻列表 getnewsinfo: 'news/getnewsinfo', //新闻详情 onlinemessage: 'message/onlinemessage', //在线留言 } // 封装ajax请求 var http = { get: function (url, params) { return new promise(function (resolve, reject) { return $.ajax({ url: api.baseurl + url, data: params || null, type: 'get', datatype: 'json', headers: {}, complete: function (response) { var res = response.responsejson if (res.code == 1) { resolve(res.data) } else if (res.code == 2) { resolve(res) } else if (res.code == -1) { resolve(res) } else { reject() } }, error: function (xhr) {} }) }) }, post: function (url, params) { return new promise(function (resolve, reject) { $.ajax({ url: api.baseurl + url, data: params || null, type: 'post', datatype: 'json', headers: {}, complete: function (response) { var res = response.responsejson if (res.code == 1) { resolve(res.data) } else { showalert(res.msg).then(function () { reject() }) } }, error: function (xhr) { reject() } }) }) } } // 获取url参数 function geturlkey(name) { return decodeuricomponent((new regexp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null; } $(function () { allhome(); }); // 统一弹窗(以防修改其他方式) function showalert(msg) { alert(msg) } // banner function allhome() { $('a').focus(function () { $(this).blur(); }); changeimages(5); //左右 //homeform(); //点击小图 $('#small_imgs a.item:first').find('div.img').addclass('active'); var allimg = $('#small_imgs .img'); var big_img = $('#big_img'); var big_a = $('#big_a'); var small_next = $('#small_next'); var stop2 = false; allimg.mouseover(function () { if ($(this).hasclass('active')) return; allimg.removeclass('active'); $(this).addclass('active'); var img = $(this).attr('b'); var link = $(this).attr('l'); var theid = $(this).attr('theid'); if (big_img.queue('fx').length != 0) { big_img.stop(true); } big_img.animate({ 'opacity': '0.2' }, 400, function () { big_img.css('background-image', 'url(' + img + ')'); if (link == '') { big_a.attr('href', 'javascript:;').attr('onclick', "pgvsendclick({hottag:'hrtencent.home.banner.banner" + theid + "'});").addclass('cdefault'); } else { big_a.attr('href', link).attr('onclick', "pgvsendclick({hottag:'hrtencent.home.banner.banner" + theid + "'});").removeclass('cdefault'); } big_img.animate({ 'opacity': '1' }, 700); }); }); $('#home_banner').mouseover(function () { stop2 = true; }).mouseout(function () { stop2 = false; }); var marquee2 = autoswitchhomebanner(allimg); mymar2 = setinterval(marquee2, 6000); function autoswitchhomebanner(allimg) { return (function () { if (stop2) return; var index = 0; $('#small_imgs .img').each(function (i) { if ($(this).hasclass('active')) { index = i; return false; } }); if (index >= 4) { small_next.click(); } var next = $('#small_imgs .img.active:first').parent().next().find('.img'); if (next.length == 0) { next = allimg.eq(0); } next.mouseover(); stop2 = false; }); } } //左右点击图片 function changeimages(allowl) { var itemall = $('#small_imgs .item'); iteml = itemall.length; if (iteml <= allowl) { // 少于最大显示数 $('#small_pre,#small_next').css('background', 'none'); return; } iteml = ((iteml - allowl) > allowl) ? allowl : (iteml - allowl); imagesswitch33('#small_pre', '#small_next', itemall, 900, iteml); } /* * 图片切换33不自动 iteml = jquery(this).find('.smallitem').length; iteml = * ((iteml-allowl)>allowl)?allow:(iteml-allowl); * imagesswitch33(pre,next,jquery(this).find('.smallitem'),900,iteml); */ function imagesswitch33(left, right, items, movetime, num) { movetime = (parseint(movetime)) ? movetime : 400; items.parent().css({ position: 'relative', overflow: 'hidden' }); items.parent().wrapinner('
'); items.parent().css('position', 'absolute'); items.parent().css('left', '0'); var offw = items.eq(0).outerwidth(true); var allw = items.outerwidth(true) * (items.length); var movew = offw * num; items.parent().width(allw + 'px'); var len = items.length; var isclick = false; jquery(left).click(function () { if (items.parent().queue('fx').length != 0) return; isclick = true; items.parent().prepend(items.parent().children().slice(len - num, len)); items.parent().css('left', '-' + movew + 'px'); items.parent().animate({ left: '+=' + movew + 'px' }, movetime, function () { items.parent().css('left', 0); }); }); jquery(right).click(function () { if (items.parent().queue('fx').length != 0) return; isclick = true; items.parent().animate({ left: '-=' + movew + 'px' }, movetime, function () { items.parent().append(items.parent().children().slice(0, num)); items.parent().css('left', 0); }); }); }