script.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. (function($) {
  2. "use strict";
  3. //Hide Loading Box (Preloader)
  4. function handlePreloader() {
  5. if($('.preloader').length){
  6. $('.preloader').delay(200).fadeOut(500);
  7. }
  8. }
  9. //Update Header Style and Scroll to Top
  10. function headerStyle() {
  11. if($('.main-header').length){
  12. var windowpos = $(window).scrollTop();
  13. var siteHeader = $('.main-header');
  14. var scrollLink = $('.scroll-to-top');
  15. if (windowpos >= 200) {
  16. siteHeader.addClass('fixed-header');
  17. scrollLink.fadeIn(300);
  18. } else {
  19. siteHeader.removeClass('fixed-header');
  20. scrollLink.fadeOut(300);
  21. }
  22. }
  23. }
  24. headerStyle();
  25. //Submenu Dropdown Toggle
  26. if($('.main-header li.dropdown ul').length){
  27. $('.main-header li.dropdown').append('<div class="dropdown-btn"><span class="fa fa-angle-down"></span></div>');
  28. //Dropdown Button
  29. $('.main-header li.dropdown .dropdown-btn').on('click', function() {
  30. $(this).prev('ul').slideToggle(500);
  31. });
  32. //Dropdown Menu / Fullscreen Nav
  33. $('.fullscreen-menu .navigation li.dropdown > a').on('click', function() {
  34. $(this).next('ul').slideToggle(500);
  35. });
  36. //Disable dropdown parent link
  37. $('.navigation li.dropdown > a').on('click', function(e) {
  38. e.preventDefault();
  39. });
  40. //Disable dropdown parent link
  41. $('.main-header .navigation li.dropdown > a,.hidden-bar .side-menu li.dropdown > a').on('click', function(e) {
  42. e.preventDefault();
  43. });
  44. }
  45. //Hidden Sidebar
  46. if ($('.hidden-bar,.fullscreen-menu').length) {
  47. var hiddenBar = $('.hidden-bar');
  48. var hiddenBarOpener = $('.nav-toggler');
  49. var hiddenBarCloser = $('.hidden-bar-closer,.close-menu');
  50. $('.hidden-bar-wrapper').mCustomScrollbar();
  51. //Show Sidebar
  52. hiddenBarOpener.on('click', function () {
  53. $('body').addClass('visible-menu-bar');
  54. hiddenBar.addClass('visible-sidebar');
  55. });
  56. //Hide Sidebar
  57. hiddenBarCloser.on('click', function () {
  58. $('body').removeClass('visible-menu-bar');
  59. hiddenBar.removeClass('visible-sidebar');
  60. });
  61. }
  62. //Event Countdown Timer
  63. if($('.time-countdown').length){
  64. $('.time-countdown').each(function() {
  65. var $this = $(this), finalDate = $(this).data('countdown');
  66. $this.countdown(finalDate, function(event) {
  67. var $this = $(this).html(event.strftime('' + '<div class="counter-column"><span class="count">%D</span>Days</div> ' + '<div class="counter-column"><span class="count">%H</span>Hours</div> ' + '<div class="counter-column"><span class="count">%M</span>Minutes</div> ' + '<div class="counter-column"><span class="count">%S</span>Seconds</div>'));
  68. });
  69. });
  70. }
  71. //Make Content Sticky
  72. //if($('.sticky-box').length){
  73. //var a = new StickySidebar('.sidebar-page-container .sidebar-side .sidebar .inner', {
  74. //topSpacing: 80,
  75. //bottomSpacing: 0,
  76. //containerSelector: '.sticky-container',
  77. //innerWrapperSelector: '.sticky-box'
  78. //});
  79. //}
  80. // Product Carousel Slider
  81. if ($('.shop-page .image-carousel').length && $('.shop-page .thumbs-carousel').length) {
  82. var $sync1 = $(".shop-page .image-carousel"),
  83. $sync2 = $(".shop-page .thumbs-carousel"),
  84. flag = false,
  85. duration = 500;
  86. $sync1
  87. .owlCarousel({
  88. loop:true,
  89. items: 1,
  90. margin: 0,
  91. nav: false,
  92. navText: [ '<span class="icon fa fa-angle-left"></span>', '<span class="icon fa fa-angle-right"></span>' ],
  93. dots: false,
  94. autoplay: true,
  95. autoplayTimeout: 5000
  96. })
  97. .on('changed.owl.carousel', function (e) {
  98. if (!flag) {
  99. flag = false;
  100. $sync2.trigger('to.owl.carousel', [e.item.index, duration, true]);
  101. flag = false;
  102. }
  103. });
  104. $sync2
  105. .owlCarousel({
  106. loop:true,
  107. margin: 20,
  108. items: 1,
  109. nav: true,
  110. navText: [ '<span class="icon fa fa-angle-left"></span>', '<span class="icon fa fa-angle-right"></span>' ],
  111. dots: false,
  112. center: false,
  113. autoplay: true,
  114. autoplayTimeout: 5000,
  115. responsive: {
  116. 0:{
  117. items:2,
  118. autoWidth: false
  119. },
  120. 400:{
  121. items:2,
  122. autoWidth: false
  123. },
  124. 600:{
  125. items:3,
  126. autoWidth: false
  127. },
  128. 900:{
  129. items:5,
  130. autoWidth: false
  131. },
  132. 1000:{
  133. items:4,
  134. autoWidth: false
  135. }
  136. },
  137. })
  138. .on('click', '.owl-item', function () {
  139. $sync1.trigger('to.owl.carousel', [$(this).index(), duration, true]);
  140. })
  141. .on('changed.owl.carousel', function (e) {
  142. if (!flag) {
  143. flag = true;
  144. $sync1.trigger('to.owl.carousel', [e.item.index, duration, true]);
  145. flag = false;
  146. }
  147. });
  148. }
  149. //Sortable Masonary with Filters
  150. function sortableMasonry() {
  151. if($('.sortable-masonry').length){
  152. var winDow = $(window);
  153. // Needed variables
  154. var $container=$('.sortable-masonry .items-container');
  155. var $filter=$('.filter-btns');
  156. $container.isotope({
  157. filter:'*',
  158. masonry: {
  159. columnWidth : '.masonry-item'
  160. },
  161. animationOptions:{
  162. duration:500,
  163. easing:'linear'
  164. }
  165. });
  166. // Isotope Filter
  167. $filter.find('li').on('click', function(){
  168. var selector = $(this).attr('data-filter');
  169. try {
  170. $container.isotope({
  171. filter : selector,
  172. animationOptions: {
  173. duration: 500,
  174. easing : 'linear',
  175. queue : false
  176. }
  177. });
  178. } catch(err) {
  179. }
  180. return false;
  181. });
  182. winDow.bind('resize', function(){
  183. var selector = $filter.find('li.active').attr('data-filter');
  184. $container.isotope({
  185. filter : selector,
  186. animationOptions: {
  187. duration: 500,
  188. easing : 'linear',
  189. queue : false
  190. }
  191. });
  192. });
  193. var filterItemA = $('.filter-btns li');
  194. filterItemA.on('click', function(){
  195. var $this = $(this);
  196. if ( !$this.hasClass('active')) {
  197. filterItemA.removeClass('active');
  198. $this.addClass('active');
  199. }
  200. });
  201. }
  202. }
  203. sortableMasonry();
  204. //Jquery Spinner / Quantity Spinner
  205. if($('.quantity-spinner').length){
  206. $("input.quantity-spinner").TouchSpin({
  207. verticalbuttons: true
  208. });
  209. }
  210. //Accordion Box
  211. if($('.accordion-box').length){
  212. $(".accordion-box").on('click', '.acc-btn', function() {
  213. var outerBox = $(this).parents('.accordion-box');
  214. var target = $(this).parents('.accordion');
  215. if($(this).hasClass('active')!==true){
  216. $(outerBox).find('.accordion .acc-btn').removeClass('active');
  217. }
  218. if ($(this).next('.acc-content').is(':visible')){
  219. return false;
  220. }else{
  221. $(this).addClass('active');
  222. $(outerBox).children('.accordion').removeClass('active-block');
  223. $(outerBox).find('.accordion').children('.acc-content').slideUp(300);
  224. target.addClass('active-block');
  225. $(this).next('.acc-content').slideDown(300);
  226. }
  227. });
  228. }
  229. //Bottom Parallax
  230. function bottomParallax() {
  231. if($('.bottom-parallax').length){
  232. var windowpos = $(window).scrollTop();
  233. var siteFooter = $('.main-footer').height();
  234. var sitebodyHeight = $('.page-wrapper').height();
  235. var finalHeight = sitebodyHeight - siteFooter - 580;
  236. if (windowpos >= finalHeight) {
  237. $('body').addClass('parallax-visible');
  238. } else {
  239. $('body').removeClass('parallax-visible');
  240. }
  241. }
  242. }
  243. bottomParallax();
  244. //Gallery Filters
  245. if($('.filter-list').length){
  246. $('.filter-list').mixItUp({});
  247. }
  248. //Tabs Box
  249. if($('.tabs-box').length){
  250. $('.tabs-box .tab-buttons .tab-btn').on('click', function(e) {
  251. e.preventDefault();
  252. var target = $($(this).attr('data-tab'));
  253. if ($(target).is(':visible')){
  254. return false;
  255. }else{
  256. target.parents('.tabs-box').find('.tab-buttons').find('.tab-btn').removeClass('active-btn');
  257. $(this).addClass('active-btn');
  258. target.parents('.tabs-box').find('.tabs-content').find('.tab').fadeOut(0);
  259. target.parents('.tabs-box').find('.tabs-content').find('.tab').removeClass('active-tab');
  260. $(target).fadeIn(300);
  261. $(target).addClass('active-tab');
  262. }
  263. });
  264. }
  265. //Fact Counter + Text Count
  266. if($('.count-box').length){
  267. $('.count-box').appear(function(){
  268. var $t = $(this),
  269. n = $t.find(".count-text").attr("data-stop"),
  270. r = parseInt($t.find(".count-text").attr("data-speed"), 10);
  271. if (!$t.hasClass("counted")) {
  272. $t.addClass("counted");
  273. $({
  274. countNum: $t.find(".count-text").text()
  275. }).animate({
  276. countNum: n
  277. }, {
  278. duration: r,
  279. easing: "linear",
  280. step: function() {
  281. $t.find(".count-text").text(Math.floor(this.countNum));
  282. },
  283. complete: function() {
  284. $t.find(".count-text").text(this.countNum);
  285. }
  286. });
  287. }
  288. },{accY: 0});
  289. }
  290. //Main Slider Carousel
  291. if ($('.main-slider-carousel').length) {
  292. $('.main-slider-carousel').owlCarousel({
  293. animateOut: 'fadeOut',
  294. animateIn: 'fadeIn',
  295. loop:true,
  296. margin:0,
  297. nav:true,
  298. autoHeight: true,
  299. smartSpeed: 500,
  300. autoplay: 6000,
  301. navText: [ '<span class="flaticon-left-arrow"></span>', '<span class="flaticon-right-arrow"></span>' ],
  302. responsive:{
  303. 0:{
  304. items:1
  305. },
  306. 600:{
  307. items:1
  308. },
  309. 800:{
  310. items:1
  311. },
  312. 1024:{
  313. items:1
  314. },
  315. 1200:{
  316. items:1
  317. }
  318. }
  319. });
  320. }
  321. // Four Item Carousel
  322. if ($('.four-item-carousel').length) {
  323. $('.four-item-carousel').owlCarousel({
  324. loop:true,
  325. margin:0,
  326. nav:true,
  327. autoHeight: true,
  328. smartSpeed: 500,
  329. autoplay: 5000,
  330. navText: [ '<span class="fa fa-angle-left"></span>', '<span class="fa fa-angle-right"></span>' ],
  331. responsive:{
  332. 0:{
  333. items:1
  334. },
  335. 600:{
  336. items:2
  337. },
  338. 800:{
  339. items:2
  340. },
  341. 1024:{
  342. items:3
  343. },
  344. 1200:{
  345. items:4
  346. }
  347. }
  348. });
  349. }
  350. // Sponsors Carousel
  351. if ($('.sponsors-carousel').length) {
  352. $('.sponsors-carousel').owlCarousel({
  353. loop:true,
  354. margin:30,
  355. nav:true,
  356. smartSpeed: 500,
  357. autoplay: 4000,
  358. navText: [ '<span class="fa fa-angle-left"></span>', '<span class="fa fa-angle-right"></span>' ],
  359. responsive:{
  360. 0:{
  361. items:1
  362. },
  363. 480:{
  364. items:2
  365. },
  366. 600:{
  367. items:4
  368. },
  369. 800:{
  370. items:5
  371. },
  372. 1024:{
  373. items:5
  374. }
  375. }
  376. });
  377. }
  378. //Verticle Carousel
  379. if($('.verticle-carousel').length){
  380. $('.verticle-carousel').slick({
  381. dots: true,
  382. autoplay: true,
  383. loop:true,
  384. autoplaySpeed: 5000,
  385. infinite: true,
  386. responsive: true,
  387. slidesToShow: 3,
  388. vertical:true,
  389. slidesToScroll: 1
  390. });
  391. }
  392. //Single Vertical Carousel
  393. if($('.single-vertical-carousel').length){
  394. $('.single-vertical-carousel').slick({
  395. dots: true,
  396. autoplay: true,
  397. loop:true,
  398. autoplaySpeed: 5000,
  399. infinite: true,
  400. responsive: true,
  401. slidesToShow: 1,
  402. vertical:true,
  403. slidesToScroll: 1,
  404. prevArrow:"<div class='prev-btn'><span class='fa fa-angle-up'></span></div>",
  405. nextArrow:"<div class='next-btn'><span class='fa fa-angle-down'></span></div>"
  406. });
  407. }
  408. //LightBox / Fancybox
  409. if($('.lightbox-image').length) {
  410. $('.lightbox-image').fancybox({
  411. openEffect : 'fade',
  412. closeEffect : 'fade',
  413. helpers : {
  414. media : {}
  415. }
  416. });
  417. }
  418. //Contact Form Validation
  419. if($('#contact-form').length){
  420. $('#contact-form').validate({
  421. rules: {
  422. name: {
  423. required: true,
  424. maxlength: 10
  425. },
  426. email: {
  427. required: false,
  428. email: true
  429. },
  430. phone: {
  431. required: true,
  432. pattern: /^1[3|4|5|6|7|8|9]{1}[\d]{9}$/
  433. },
  434. title: {
  435. required: false,
  436. maxlength: 15
  437. },
  438. description: {
  439. required: false,
  440. maxlength: 100
  441. }
  442. },
  443. messages: {
  444. name: {
  445. required: '姓名为必填项'
  446. },
  447. phone: {
  448. required: '手机号为必填项',
  449. pattern: '手机号格式不正确'
  450. },
  451. email: {
  452. email: '邮箱格式不正确'
  453. },
  454. subject: {
  455. maxlength: '标题长度不能超过20个字'
  456. }
  457. },
  458. submitHandler:function(form){
  459. form.submit();
  460. alert("提交成功,稍后会有专人与您取得联系,请保持手机畅通!");
  461. }
  462. });
  463. }
  464. // Scroll to a Specific Div
  465. if($('.scroll-to-target').length){
  466. $(".scroll-to-target").on('click', function() {
  467. var target = $(this).attr('data-target');
  468. // animate
  469. $('html, body').animate({
  470. scrollTop: $(target).offset().top
  471. }, 1500);
  472. });
  473. }
  474. // Elements Animation
  475. if($('.wow').length){
  476. var wow = new WOW(
  477. {
  478. boxClass: 'wow', // animated element css class (default is wow)
  479. animateClass: 'animated', // animation css class (default is animated)
  480. offset: 0, // distance to the element when triggering the animation (default is 0)
  481. mobile: true, // trigger animations on mobile devices (default is true)
  482. live: true // act on asynchronously loaded content (default is true)
  483. }
  484. );
  485. wow.init();
  486. }
  487. /* ==========================================================================
  488. When document is Scrollig, do
  489. ========================================================================== */
  490. $(window).on('scroll', function() {
  491. headerStyle();
  492. bottomParallax();
  493. });
  494. /* ==========================================================================
  495. When document is loading, do
  496. ========================================================================== */
  497. $(window).on('load', function() {
  498. handlePreloader();
  499. sortableMasonry();
  500. });
  501. $('#menu-operate-spread').click(function () {
  502. $(this).hide();
  503. $('#menu-operate-close').show();
  504. $('.hx-menu').show();
  505. });
  506. $('#menu-operate-close').click(function () {
  507. $(this).hide();
  508. $('#menu-operate-spread').show();
  509. $('.hx-menu').hide();
  510. });
  511. $(window).resize(function() {
  512. var window_width = $(window).width();//获取浏览器窗口宽度
  513. if(window_width>=1200){
  514. $('.hx-menu').show();
  515. }else{
  516. $('.hx-menu').hide();
  517. }
  518. $('#menu-operate-spread').show();
  519. $('#menu-operate-close').hide();
  520. });
  521. })(window.jQuery);