(function($){ /* 回到購買處 */ $('.gobuy').on('click',function(){ var tol = $(window).height(); console.log(tol); var buy = $('.button-line').offset().top-tol+50 ; $("html,body").scrollTop(buy); }); /*為JQ添加naturalWidth()和naturalHeight()方法,抓取圖片原始尺寸*/ var props = ['Width', 'Height'], prop; while (prop = props.pop()) { (function (natural, prop) { $.fn[natural] = (natural in new Image()) ? function () { return this[0][natural]; } : function () { var node = this[0], img, value; if (node.tagName.toLowerCase() === 'img') { img = new Image(); img.src = node.src, value = img[prop]; } return value; }; }('natural' + prop, prop.toLowerCase())); } }(jQuery)); // ========================================================== // 下方商品輪播 // ========================================================== $(function(){ const carouselTarget = $('.detail-bottom .product-simple-list .wrapper') if(carouselTarget.length){ carouselTarget.each(function(){ let list = $(this) simpleProductList(list) $(window).on("resize", function(){ simpleProductList(list) }) }) } }) // ========================================================== // 手機版固定選單出現時間判斷 // ========================================================== ;(function($) { $(window).on('scroll', function(e) { e.preventDefault() const fixedOffset = $('.productTitle').offset().top const fixedTarget = $('.fixed-button') if($(window).scrollTop() > fixedOffset) { fixedTarget.removeClass('hide') } else { fixedTarget.addClass('hide') } }) })($) // ========================================================== // trigger function // ========================================================== ;(function($, jQuery, window, document) { $(window).triggerAll('resize scroll') })($, jQuery, window, document) // ========================================================== // 複製連結 // ========================================================== $(function(){ $(document).on("click", ".copy-btn", function(e){ e.preventDefault() navigator.clipboard.writeText($($(this).data("target")).val()) alert("複製連結成功") }) }) // ========================================================== // 行銷活動展開 // ========================================================== ;(function($) { $(".sale-wrapper").on("click", ".view-all-btn", function(){ $(".sale-wrapper").toggleClass("in-collapse") }) })($)