$(document).ready(function () { $.plugin = { NUMBER_plus: function (obj, set_num, speed) { if (!speed) speed = 60; if (!set_num) set_num = 50; var scroll_lock = true; $(window).scroll(function () { if ($(document).scrollTop() + $(window).height() > obj.offset().top && obj.offset().top + obj.innerHeight() > $(document).scrollTop() && scroll_lock) { scroll_lock = false; var time_lock = 0, This = obj.find('li'), // 获取对象 num = []; // 数据容器 var set_plus = setInterval(function () { // 数字相加 This.each(function (index) { if (!num[index]) num[index] = $(this).find('em').attr('data-num')*1/set_num; else num[index] += $(this).find('em').attr('data-num')*1/set_num; $(this).find('em').text(parseInt(num[index])); if (num[index] > $(this).find('em').attr('data-num')*1) { $(this).find('em').text($(this).find('em').attr('data-num')*1); time_lock++; } }); if (time_lock >= num.length) { // 清理多余执行 clearInterval(set_plus); } }, speed); } }) }, BG_parallax: function (obj, speed) { if (!speed) speed = .5; $(window).scroll(function () { obj.css({ 'background-position-y': (((obj.offset().top + obj.innerHeight() / 2) - ($(document).scrollTop() + $(window).height() / 2)) * speed) }) }) }, Interval_Fun: function (obj, means, cycle, position) { if (!position) position = 2; if (!cycle) var cycle_num = 0; $(window).scroll(function () { if (obj.offset().top + obj.innerHeight() / position < $(document).scrollTop() + $(window).height() && obj.offset().top + obj.innerHeight() / position > $(document).scrollTop()) { cycle_num++; if (!cycle && cycle_num <= 1) means(); else if (cycle) means() } }) }, Video_open: function (obj) { var src, btn, img, tag, method = obj.attr('data-mode'); if (obj.attr('data-src')) src = obj.attr('data-src'); else return; if (obj.attr('data-img')) img = obj.attr('data-img'); btn = obj.attr('data-btn') ? obj.attr('data-btn') : '#000'; if (!method) tag = ''; else tag = ''; var video = "
" + tag + "
", css = "" obj.click(function () { $("body").append(video).append(css).animate(200, function () { $(".video_box").add($(".video_mask")).removeClass('active'); }); $("i.video_mask").add($("i.video_close")).one('click', function () { $(".video_box").add($("i.video_mask")).add($("#video_css")).remove(); }) }); }, Pop_Ups: function(obj,model,btn_,lang){ lang = { lang:window.location.hostname.split('.')[0], title:'Submit feedback', name:'Name', mail:'Email', phone:'Phone', message:'Message', send:'Send' } switch (lang.lang) { case 'cn': lang['title'] = '留言反馈';lang['name'] = '姓名';lang['mail'] = '邮箱';lang['phone'] = '电话';lang['message'] = '留言内容';lang['send'] = '立即提交'; break; case 'ru': lang['title'] = 'Обратная связь';lang['name'] = 'Имя';lang['mail'] = 'Почта';lang['phone'] = 'телефон';lang['message'] = 'Содержание сообщения';lang['send'] = 'Отправить сейчас'; break; case 'es': lang['title'] = 'Realimentación';lang['name'] = 'Nombre';lang['mail'] = 'Correo';lang['phone'] = 'Teléfono';lang['message'] = 'Contenido del mensaje';lang['send'] = 'Aplique ahora'; break; case 'sa': lang['title'] = 'ردود الفعل';lang['name'] = 'اسم';lang['mail'] = 'بريد';lang['phone'] = 'هاتف';lang['message'] = 'محتوى الرسالة';lang['send'] = 'أرسل الآن'; break; case 'de': lang['title'] = 'Feedback';lang['name'] = 'Name';lang['mail'] = 'Email';lang['phone'] = 'Telefon';lang['message'] = 'Nachrichteninhalt';lang['send'] = 'Jetzt Absenden'; break; case 'jp': lang['title'] = 'フィードバック';lang['name'] = '名前';lang['mail'] = 'Eメール';lang['phone'] = '電話';lang['message'] = 'メッセージの内容';lang['send'] = '今提出'; break; case 'kr': lang['title'] = '피드백';lang['name'] = '이름';lang['mail'] = '우편';lang['phone'] = '전화';lang['message'] = '메시지 내용';lang['send'] = '지금 제출'; break; case 'fr': lang['title'] = 'Retour d\'information';lang['name'] = 'Nom';lang['mail'] = 'Courrier';lang['phone'] = 'Téléphone';lang['message'] = 'Contenu du message';lang['send'] = 'Soumettre maintenant'; break; } var css = '', html = '', btn = '
', lock = true, model_form = false, model_url = ''; $("body").append(css).append(html); $.getScript('/static/js/layer/layer.js',function (response,status) { if (status==='success') { lock = false; } }); if (btn_) { $("body").append(btn); } (obj?obj:$("#Pop_UpsBtn")).on('click',function (e) { if (model && !model_form) { e.preventDefault(); e.stopPropagation(); model_url = $(this).attr('href')?$(this).attr('href'):$(this).find('a').attr('href'); } if (!model_form) $("#pups_from").stop().fadeToggle(200); }); $("#pups_from i.close").on('click',function () { $("#pups_from").stop().fadeToggle(200); }); $("#pups_from form input[type=submit]").on('click',function () { layer.load(0,{shade:0.1,shadeClose:false}); $.ajax({ type: 'post', url: '/Api/contact/submit/uid/1.html', data: $("#pups_from form").serialize(), dataType: 'json', success: function (data) { layer.closeAll(); if (data.status == 200) { //layer.msg(data.result,{icon:1,time:4000}); window.location.href="/inquire-success/"; if (model && !model_form) { model_form = true; $("#pups_from").stop().fadeToggle(200); var a = document.createElement('a'); a.setAttribute('href',model_url); a.setAttribute('download',''); document.body.appendChild(a); a.click(); a.remove(); } } else { layer.msg(data.result,{icon:2,time:4000}) } } }) }); }, Line_curve: function (obj, origin, coordinate, color,img, speed) { if (!speed) speed = 0.01; if (!color) color = '#000'; var con = document.getElementById(obj).appendChild(document.createElement('canvas')); var ctx = con.getContext('2d'); con.width = document.getElementById(obj).offsetWidth ? document.getElementById(obj).offsetWidth : window.innerWidth; con.height = document.getElementById(obj).offsetHeight ? document.getElementById(obj).offsetHeight : window.innerHeight; var percent = 0; ctx.lineWidth = 2; origin = [origin[0] * (con.width / 100), origin[1] * (con.height / 100)]; function animate() { ctx.clearRect(0, 0, con.width, con.height); ctx.drawImage(img,0,0,con.width,con.height); for (var i = 0; i < coordinate.length; i++) { var x0 = coordinate[i][0][0] * (con.width / 100); var y0 = coordinate[i][0][1] * (con.height / 100); var x1 = coordinate[i][1][0] * (con.width / 100); var y1 = coordinate[i][1][1] * (con.height / 100); ctx.strokeStyle = color; ctx.beginPath(); formula(ctx, origin, [x0, y0], [x1, y1], percent); ctx.stroke(); } if (percent < 1) percent += speed; else { return; } requestAnimationFrame(animate); } function formula(ctx, start, end, control, percent) { // 二次贝塞尔曲线坐标计算公式 var v01 = [control[0] - start[0], control[1] - start[1]]; // 向量 var v12 = [end[0] - control[0], end[1] - control[1]]; // 向量 var q0 = [start[0] + v01[0] * percent, start[1] + v01[1] * percent]; var q1 = [control[0] + v12[0] * percent, control[1] + v12[1] * percent]; var v = [q1[0] - q0[0], q1[1] - q0[1]]; // 向量 var b = [q0[0] + v[0] * percent, q0[1] + v[1] * percent]; ctx.moveTo(start[0], start[1]); ctx.quadraticCurveTo( q0[0], q0[1], b[0], b[1] ); } animate(); }, shopping_cart: function (text_, element, cart_page,product) { // 对象数据汇总 if (!cart_page) cart_page = false; if (!element) { element = { shopping_cart: '.shopping_cart', shopping_form: '.shopping_form', shopping_list: '.shopping_list', product_box: '.product_box', //多增加一个data-id 属性 product_name: '.product_name', product_link: '.product_link', product_det: '.product_det', product_img: '.product_img', product_tag: '.product_tag', product_add: '.product_add' }; } if (!text_) { text_ = { close: 'Close All', title: 'Feedback', submit: 'Send', number: 'Number:', cart: 'There are no products, just add them!', required: 'Can not be empty!' } } var css = '', html = ''; // 初始化 var data = [], lock = true; if ($.cookie !== undefined) { if ($.cookie('the_product_info') !== undefined && $.cookie('the_product_info') !== '') { data = $.cookie('the_product_info').split('?'); } } else { alert('需要cookie插件支持!'); return; } $(element.shopping_cart).find('em').html(data.length); // 列表 function click_car(T) { lock = true; var name = T.parents(element.product_box).find(element.product_name).length ? T.parents(element.product_box).find(element.product_name).text() : '', url = T.parents(element.product_box).find(element.product_link).length ? T.parents(element.product_box).find(element.product_link).attr('href') : '', det = T.parents(element.product_box).find(element.product_det).length ? T.parents(element.product_box).find(element.product_det).text() : '', img = T.parents(element.product_box).find(element.product_img).length ? T.parents(element.product_box).find(element.product_img).attr('src') : '', tag = T.parents(element.product_box).find(element.product_tag).length ? T.parents(element.product_box).find(element.product_tag).children('*') : ''; if ($.isArray(data)) { data.map(function (value, index) { var key = Object.keys(JSON.parse(value))[0]; if (key === T.parents(element.product_box).attr('data-id')) { lock = false; data.splice(index, 1); } }); } var tag_arr = []; if (tag !== '') { tag.filter(function () { tag_arr.push($(this).text()) }); } var text = '{"' + T.parents(element.product_box).attr('data-id') + '":{"name":"' + name.replace(/\s/g, " ") + '","url":"' + url + '","det":"' + det + '","img":"' + img + '","tag":"' + tag_arr.join('/') + '"}}'; if (lock) { data.push(text); } $(element.shopping_cart).find('em').html(data.length); $.cookie('the_product_info', data.join('?'), {path: '/'}); } $(document).on('click', element.product_add, function (e) { click_car($(this)); $(this).toggleClass('active'); }); function cart_detect() { data.map(function (value, index) { var detect = JSON.parse(value); $(element.product_box).filter(function () { if (Object.keys(detect)[0] === $(this).attr('data-id')) { $(this).find(element.product_add).addClass('active') } }) }); } //购物车 function Structure_injection() { if (cart_page) { return data; }else { var data_ = []; $(element.shopping_list).html(''); data.map(function (value, index) { data_ = JSON.parse(value); $(element.shopping_list).append('
  • \n' + '
    \n' + '
    \n' + '
    \n' + '

    ' + data_[Object.keys(data_)[0]].name + '

    ' + text_.number + '

    \n' + ' \n' + ' \n' + ' \n' + '
    \n' + '
    \n' + '
  • ') }); } } function cart() { if (!cart_page) { $('body').append(html,css); $.getScript('/static/js/layer/layer.js'); Structure_injection(); $(document).on('click','#cart i.del', function (e) { var info_ = $(this).parents('li'); if (data.length) { data.splice(info_.index(), 1); $(element.shopping_cart).find('em').html(data.length); $.cookie('the_product_info', data.join('?'), {path: '/'}); info_.remove(); if (!data.length) { $(element.shopping_list).html(text_.cart); } } }); $(document).on('blur','#cart input', function (e) { if ($(this).val() === '') { layer.msg(text_.required, {icon: 2, time: 4000}); } }) $(document).on('click','#cart input[type=\'submit\']', function (e) { e.preventDefault(); var content = ''; $(element.shopping_list).find('li').filter(function () { content += '\n' + $(this).find('h4').text() + '\n' + 'Qty:' + $(this).find('input').val() + '\n' + 'Message:' + $(this).find('textarea').val() + '\n' + 'Url:' + $(this).find('a').attr('href') + '\n' + '-------------------------------------------\n' }); var textarea = $(element.shopping_form).find("textarea").val(); $(element.shopping_form).find("textarea").val(textarea + content); layer.load(0, {shade: 0.1, shadeClose: false}); $.ajax({ type: 'post', url: '/Api/contact/submit/uid/1.html', data: $(element.shopping_form).find('form').serialize(), dataType: 'json', success: function (ret) { layer.closeAll(); $(element.shopping_form).find("textarea").val(textarea); if (ret.status == 200) { layer.msg(ret.result, {icon: 1, time: 4000}); $(element.shopping_cart).find('em').html(0); $.cookie('the_product_info', '', {path: '/'}); } else { layer.msg(ret.result, {icon: 2, time: 4000}) } } }) }); $(document).on('click','#cart span.close_all', function (e) { $(element.shopping_list).find('li').remove(); $(element.shopping_cart).find('em').html(0); $.cookie('the_product_info', '', {path: '/'}); }); $(document).on('click',element.shopping_cart, function (e) { $("#cart").fadeIn(300); Structure_injection(); }) $(document).on('click','#cart i.fa-close', function (e) { $("#cart").fadeOut(300) }) }else { product(Structure_injection()) } } cart_detect(); cart(); } }; $.plugin.Pop_Ups(false,false,true) /** * 全局效果说明 * ---------------------Dividing line-------------------- * @num_plus 数字相加 * 参数 (obj,set_num,speed = 60) * 详解 obj * 获取容器对象 * set_num * 设置相加比例 公式: 数字 / set_num = 每次相加数字(整数) * speed * 动画速度 默认 60ms * html 结构 *
      *
    • *0*
    • *
    * * ---------------------Dividing line-------------------- * @BG_parallax 背景视差 * 参数 (obj,speed = 0.5) * 详解 obj * 获取容器对象 * speed * 动画速度 默认 0.5 * * ---------------------Dividing line-------------------- * @Interval_Fun 区间判断 * 参数 (obj,means,cycle,position) * 详解 obj * 获取容器对象 * means * 执行方法 * cycle * 是否多次执行 boolean值 * position * 当容器自身多少出现在屏幕中时执行 公式:容器高度 / position * * ---------------------Dividing line-------------------- * @Video_open 视频弹窗 * 参数 (obj,url,btn,img) * 详解 obj * 获取点击对象 ( html标签 data-src="视频地址" data-img="video第一帧" data-btn="关闭按钮颜色") * method * 切换模式 (video / iframe) false / true * * ---------------------Dividing line-------------------- * @Line_curve 画曲线 * 参数 (obj,origin,coordinate,color,speed) * 详解 obj * 获取ID属性 * origin * 中心点 (数组) 百分比 * coordinate * 其它点 (控制点+终点) * [ * [[终点],[控制点]] 百分比 * ] * color * 线条颜色 * img * 图片 * speed * 速度 * @shopping_cart 伪购物车 * 参数 (text_, element, cart_page = false) * 详解 text_ = { close: 'Close All', title: 'Feedback', submit: 'Send', number: 'Number:', cart: 'There are no products, just add them!', required: 'Can not be empty!' } cart_page 是否启用自定义购物弹窗 product 不启用时 返回数据 注意 若提交失败 检查是否存在对应字段 * */ })