$(function (){ function slideCounter(target, nextClassName, itemLength) { const itemIndex = $(target).find('.owl-dot.active').index() $(target).next(nextClassName).text(`${itemIndex + 1} / ${itemLength}`) } // 首頁主廣告 if($("#slideshow .slide-item").length >= 1){ const owlSlide = $("#slideshow") owlSlide.owlCarousel({ loop : true, items : 1, nav : true, navText : ['',''], dots:true, autoplay:true, navSpeed:1000, autoplayTimeout:8000, autoplaySpeed:1000, dotsSpeed:1000, }); const itemLength = owlSlide.find('.owl-dot').length owlSlide.on('refreshed.owl.carousel', function(e) { slideCounter(this, '.slideshow-counter', itemLength) }) owlSlide.on('translated.owl.carousel', function(e) { slideCounter(this, '.slideshow-counter', itemLength) }) owlSlide.trigger('refresh.owl.carousel') } // 今日優惠 slide 設定 if($(".today-wrapper").length){ $(".today-wrapper").each(function(i, item) { const owlSlide = $(item) if(owlSlide.children('.slide-item').length > 1) { owlSlide.owlCarousel({ autoplay: true, autoplaySpeed: 1000, autoplayTimeout: 8000, dots: false, items: 1, loop: true, nav: true, navSpeed: 1000, navText: ['',''], }) } }) } // 暢銷熱賣 tag 切換樣式功能 $('.labelBox').on('click', '.sellhot-label', function(e) { $(this).addClass('in-checked').siblings('.sellhot-label').removeClass('in-checked') }) // lookbook(頁中 slide) if($('.lookbook .slidebox').children().length >= 1) { const lookbookSlide = $('.lookbook .slidebox') lookbookSlide.owlCarousel({ items: 1, nav: true, dots: true, loop: true, autoplay: true, }) const itemLength = lookbookSlide.find('.owl-dot').length lookbookSlide.on('refreshed.owl.carousel', function(e) { slideCounter(this, '.slideshow-counter', itemLength) }) lookbookSlide.on('translated.owl.carousel', function(e) { slideCounter(this, '.slideshow-counter', itemLength) }) lookbookSlide.trigger('refresh.owl.carousel') } // 影音、試用評價 $('.video-002 .wrapper, .review-001 .wrapper').owlCarousel({ responsive:{ 0:{ items: 1 }, 481:{ items: 2 }, 769:{ items: 3 }, 1201: { items: 4 } }, nav : true, navText : ['',''], dots: false, slideBy: 'page', margin: 20, }); }); // ========================================================== // owl slide 響應切換 // ========================================================== ;(function($) { let deviceStep = '' const newProduct = $('.slide-wrapper') // 新品、排行 const hotSale = $('.slideBox') // 熱賣 $(window).on('resize', function(e) { if ($(this).width() > 660 && deviceStep !== 'tablet') { deviceStep = 'tablet' newProduct.each(function(i, item) { $(item).owlCarousel({ responsive: { 0: { items: 3, margin: 20, }, 1025: { items: 4, margin: 50, } }, nav: true, dots: false, slideBy: 'page', }) }) hotSale.each(function(i, item) { $(item).owlCarousel({ responsive: { 0: { items: 3, margin: 20, }, 1025: { items: 4, margin: 50, } }, nav: true, dots: false, slideBy: 'page', }) }) } else if ($(this).width() <= 660 && deviceStep !== 'mobile') { deviceStep = 'mobile' newProduct.each(function(i, item) { if ($(item).data('owl.carousel')) { $(item).data('owl.carousel').destroy() } }) hotSale.each(function(i, item) { if ($(item).data('owl.carousel')) { $(item).data('owl.carousel').destroy() } }) } }) $(window).trigger('resize') })($) // ========================================================== // 沒有每日優惠時的樣式處理 // ========================================================== ;(function($) { const todaySale = $('.actAndColumn .today-wrapper') if(!todaySale.children().length) { $('.actAndColumn').addClass('no-todaySale') } else { $('.actAndColumn').removeClass('no-todaySale') } })($) // ========================================================== // 影片操作 // ========================================================== ;(function($) { const player = $('.videobox') player.on('click', function (e) { const targetChild = $(this).children('.video')[0] if ($(this).hasClass('in-play')) { player.removeClass('in-play'); youtubeControl(targetChild, 'stop') } else { $('.video').each(function (i, ele) { youtubeControl($(ele)[0], 'stop') }); player.removeClass('in-play'); $(this).addClass('in-play') youtubeControl(targetChild, 'play') } }); $('.video-002 .wrapper').on('changed.owl.carousel', function(e) { $('.video').each(function (i, ele) { youtubeControl($(ele)[0], 'stop') }); }) function youtubeControl(target, state) { target.contentWindow.postMessage(`{"event":"command","func":"${state}Video","args":""}`, '*'); } })($)