$(function(){ $(window).scroll(function(){ if($(this).scrollTop() > 100){ $(".top_btn").fadeIn(); }else{ $(".top_btn").fadeOut(); } }); $(".top_btn").click(function(){ $("html, body").animate({ scrollTop: 0 }, 1000); }); var x, y, top, left, down; $(".sub_tab_wrap ul").mousedown(function(e) { e.preventDefault(); down = true; x = e.pageX; y = e.pageY; left = $(this).scrollLeft(); $(this).addClass("grabbing"); }); $(".sub_tab_wrap ul li a").mouseup(function(e) { e.preventDefault(); }); $(".sub_tab_wrap ul").mousemove(function(e) { if(down){ var newX = e.pageX; var newY = e.pageY; $(".sub_tab_wrap ul").scrollLeft(left - newX + x); } }); $(".sub_tab_wrap ul li a").click(function(e) { e.preventDefault(); }); $(".sub_tab_wrap ul li a").mouseup(function(e) { down = false; $(this).removeClass("grabbing"); var newerX = e.pageX; if(newerX !== x) { }else{ var $href = $(this).attr("href"); if($href !== undefined){ window.location = this.href; }; }; }); // 서브 탭 스크롤 var pageList = ".sub_tab_wrap ul"; var pageListFadeEl = ".scroll_fade"; var pageListItem = ".sub_tab_wrap ul li"; $(pageList).on("scroll", function() { console.log($(this)[0].offsetWidth); var scrollLeft = $(this).scrollLeft(); var pageListWidth = $(this)[0].scrollWidth - $(this)[0].offsetWidth; if(scrollLeft === pageListWidth){ $(this).siblings(pageListFadeEl).addClass('is-hide'); //alert("aa") } else { $(this).siblings(pageListFadeEl).removeClass('is-hide'); } }); if($(pageListItem).hasClass("on") === true){ var activeWidth = $(".sub_tab_wrap ul li.on").width(); var activeOffset = $(".sub_tab_wrap ul li.on").offset().left; $(pageList).animate({ scrollLeft: activeOffset - activeWidth }, 500); } });