/*公共js*/ /****************自适应设置**************/ /*(function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; if(clientWidth>=750){ docEl.style.fontSize = '100px'; }else{ docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'; } }; if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false); })(document, window);*/ $(document).ready(function() { $('.carton_button').on('click', function (e) { var media = document.getElementById("voMain"); var mi = $('.carton_button ').find("i"); if(mi.is(".fa-play")){ mi.removeClass("fa-play"); mi.addClass("fa-pause"); media.play(); //播放 }else{ mi.removeClass("fa-pause"); mi.addClass("fa-play"); media.pause(); //暂停 } }); // 鼠标移入移出事件 $('.logo-s').hover(function() { // 鼠标移入时添加hover类 $(this).attr("src", "jsp/main/images/logo1.png"); }, function() { // 鼠标移出时移出hover类 $(this).attr("src", "jsp/main/images/logo180.png"); }); $('.head-search-a').on('click', function (e) { $(".h-search").slideToggle("slow"); if($(".h-search").css("display")=="none"){ $("#search-input").blur(); //失去焦点 }else{ $("#search-input").focus(); //设置焦点 } }); // 鼠标移入移出事件,精选案例 $('.case-item').hover(function() { // 鼠标移入时添加hover类 $('.case-item').removeClass("active"); $(this).addClass("active"); }); /*子元素不触发 用mouseenter 和mouseleave */ $(".h-pro-a").mouseenter(function() { setTimeout(function(){ $(".h-pro-a").children(".h-product").slideDown(200); },300); }); $(".h-pro-a").mouseleave(function() { if ($('.h-product').css('display') === 'none') { } else { $(".h-pro-a").children(".h-product").slideUp(200); } }); //回车事件,搜索产品名称 $('#search-input').bind('keypress',function(event){ if(event.keyCode == "13") { let name = $('#search-input').val(); if(name !=""){ postRedirect('home/product', { name: encodeURI(encodeURI(name)) }); } } });//方法二如下 /*$(document).keydown(function(e) { if (e.keyCode == 13) { //dologin(); } });*/ $(window).scroll(function(){ var scrollTop = $(this).scrollTop(); if(scrollTop > 300){ $(".article-img").slideUp(400); }else{ $(".article-img").slideDown(400); } }); //回到顶部 $(window).scroll(function() { if ($(window).scrollTop() > 500) { $('#uiGoTop').fadeIn(500); } else { $('#uiGoTop').fadeOut(500); } }); $('#uiGoTop').on('click', function() { $('body,html').animate({ scrollTop: 0 }, 600); }); }) function postRedirect(url, params) { // 创建隐藏的form表单(jQuery方式) let $form = $('
') .attr('method', 'POST') // POST提交 .attr('action', url) // 跳转地址 .css('display', 'none'); // 隐藏表单 // 遍历参数,创建隐藏input $.each(params, function(key, value) { $('') .attr('type', 'hidden') .attr('name', key) .attr('value', value) .appendTo($form); }); // 将表单添加到页面并提交 $form.appendTo('body').submit(); } function clearSearch() { $("#search-input").val(""); $("#search-input").focus(); } function setProType(parentId){ $("#parentId").val(parentId); let typeId = $("#typeId").val(); postRedirect('home/product', { parentId: parentId, typeId: typeId }); } function setTypeParentId(typeId){ $("#typeId").val(typeId); let parentId = $("#parentId").val(); postRedirect('home/product', { parentId: parentId, typeId: typeId }); } function setProTypeAll(parentId){ $("#parentId").val(parentId); $("#typeId").val(""); postRedirect('home/product', { parentId: parentId }); } function setTypeId(id){ $("#typeId").val(id); let typeId = $("#typeId").val(); postRedirect('home/info', { typeId: typeId }); }