demand.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. @update:2018/06/04
  3. */
  4. import 'css/bootstrap.less';
  5. import 'bootstrap/dist/js/bootstrap.js';
  6. import 'css/newMenu/public.css';
  7. import 'css/newMenu/header.css'
  8. import 'css/newMenu/demand.css';
  9. import 'js/public.js';
  10. $(function () {
  11. init();
  12. function init() {
  13. nav();
  14. industryFun();
  15. search();
  16. searchFun();
  17. inpFun();
  18. }
  19. //二级导航
  20. function nav() {
  21. $('.nav ul li').mouseenter(function () {
  22. $(this).find('.subnavigation').slideDown(100);
  23. });
  24. $('.nav ul li').mouseleave(function () {
  25. $(this).find('.subnavigation').slideUp(100);
  26. $('.nav ul li').stop(false, true);
  27. });
  28. //轮播
  29. $('#myCarousel').carousel({
  30. interval: 4000
  31. })
  32. }
  33. //行业选择
  34. function industryFun() {
  35. $('.navMeau').mouseenter(function () {
  36. $(this).find('.menuList').slideDown(200);
  37. });
  38. $('.navMeau').mouseleave(function () {
  39. $(this).find('.menuList').slideUp(200);
  40. $('.navMeau').stop(false, true);
  41. });
  42. }
  43. //搜索
  44. let valArr = [],valTxt=[];
  45. function search(){
  46. $('.menuList ul li').on('click',function(){
  47. let txts = $(this).text();
  48. valArr=[];
  49. valTxt=[];
  50. inputVal(txts);
  51. })
  52. }
  53. function inputVal(item){
  54. $('.demandSearch').val('');
  55. valTxt.push(item);
  56. valArr.push(`<span>${item}</span>`);
  57. $('.demandSearch').attr('placeholder','');
  58. $('.txtVal').html(valArr);
  59. }
  60. function inpFun(){
  61. $('.demandSearch').focus(function(){
  62. if(valArr.length){
  63. valArr=[];
  64. valTxt=[];
  65. $('.txtVal').html('');
  66. }
  67. })
  68. $('.demandSearch').focus(function(){
  69. if(!valArr.length&&!($(this).val())){
  70. $('.demandSearch').attr('placeholder','输入你感兴趣的内容');
  71. }
  72. })
  73. }
  74. function searchFun(){
  75. $('.searchBtn').on('click',function(){
  76. let sVal = $('.search-inp .demandSearch').val();
  77. if(sVal){
  78. console.log(sVal);
  79. // window.location.href = globalConfig.context + '/user/account/index.html#consultList'
  80. }
  81. if(valTxt.length){
  82. console.log(valTxt.join(''))
  83. }
  84. });
  85. }
  86. })