var AROSSMN = AROSSMN || {}; (function($, APP) { $(function () { APP.Browsers.init(); APP.Devices.init(); APP.Viewport.init(); APP.ScrollTo.init(); }); // --------------------------------------------------------------------- // Browser feature check // --------------------------------------------------------------------- APP.Browsers={ init:function(){ APP.Browsers.getBrows(); }, getBrows:function() { var _ua = window.navigator.userAgent; if (_ua.match(/MSIE/) || _ua.match(/Trident/)) { this.brows = 'is_ie'; $('html').addClass('is_ie'); } else if (_ua.indexOf("Edge") > -1) { this.brows = 'is_edge'; $('html').addClass('is_edge is_ie is_ie11'); } else if (_ua.indexOf("Firefox") > -1) { this.brows = 'is_firefox'; $('html').addClass('is_firefox'); } else if (_ua.indexOf("Chrome") > -1) { this.brows = 'is_chrome'; $('html').addClass('is_chrome'); } else if (_ua.indexOf("Opera") > -1) { this.brows = 'is_opera'; $('html').addClass('is_opera'); } else if (_ua.indexOf("Safari") > -1) { this.brows = 'is_safari'; $('html').addClass('is_safari'); } else { this.brows = 'is_other'; $('html').addClass('is_other'); } return false; } }; APP.Devices={ init:function(){ } }; // --------------------------------------------------------------------- // Detect if element is in the viewport // --------------------------------------------------------------------- APP.Viewport = { init: function() { $.fn.isOnScreen = function(){ var elementTop = $(this).offset().top, elementBottom = elementTop + $(this).outerHeight(), viewportTop = $(window).scrollTop(), viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < viewportBottom; }; function detection() { for(var i = 0; i < items.length; i++) { var el = $( items[i] ); if( el.isOnScreen() ){ el.addClass('in-view'); } else { //el.removeClass('in-view'); } } } var items = document.querySelectorAll('*[data-animate-in], *[data-detect-viewport]'), waiting = false, w = $(window); w.on("resize scroll", function(){ if (waiting) { return; } waiting = true; detection(); setTimeout(function () { waiting = false; }, 100); }); w.on('load',function(){ APP.Viewport.bg_loader(); APP.Viewport.spacer(); }); $(document).ready(function(){ setTimeout(function(){ detection(); }, 500); for(var i = 0; i < items.length; i++) { var d = 0, el = $( items[i] ); if( items[i].getAttribute('data-animate-in-delay') ) { d = items[i].getAttribute('data-animate-in-delay') / 1000 + 's'; } else { d = 0; } el.css('transition-delay', d); } $("img.lazy").lazyload(); }); }, bg_loader:function(){ /* 瀹氫箟鑳屾櫙鍥綣S鍔犺浇鏂规 */ $('.js-cover').each(function(index, el) { var $this = $(el); var src = $this.data('src'); if(src){ $this.css({ 'background-image': 'url('+src+')' // 'background-position': 'center', // 'background-size': 'cover', // //'background-attachment':'fixed', // 'background-repeat':'no-repeat' }); } }); $('.js-contain').each(function(index, el) { var $this = $(el); var src = $this.data('src'); if(src) { $this.css({ 'background-image': 'url(' + src + ')' // 'background-position': 'center', // 'background-size': 'contain' }); } }); $('.js-clip').each(function(index, el) { var $this = $(el); var src = $this.data('src'); if(src) { $this.css({ 'background-image': 'url(' + src + ')' // 'background-position': 'center' }); } }); }, spacer:function(){ $('.js-spacer').each(function(index, el) { var $this = $(el); var n = $this.data('n'); if(n){ $this.css({ 'height': n*50 }); } }); } }; // --------------------------------------------------------------------- // Click Functions // --------------------------------------------------------------------- APP.ScrollTo = { init: function() { if( $('*[data-scroll-to]').length ) { this.bind(); } else { return; } }, bind: function() { $('*[data-scroll-to]').on('click touchstart:not(touchmove)', function(e) { e.preventDefault(); var trigger = $(this).attr('data-scroll-to'), target = $("#" + trigger), ss = 1000, //scroll speed o = 0; // offset if( $(this).attr('data-scroll-speed') ) { ss = $(this).attr('data-scroll-speed'); } if( $(this).attr('data-scroll-offset') ) { o = $(this).attr('data-scroll-offset'); } $('html, body').animate({ scrollTop: target.offset().top - o }, ss); }); } }; }(jQuery,AROSSMN));