// JavaScript Document // -------------------------------------------------------------------- // SPページトップ // -------------------------------------------------------------------- jQuery.fn.stwPageTop = function(){ this.each(function(){ var $btn = $(this).click(function(){ // スクロールしてトップ $('body,html').animate({ scrollTop: 0 }, 500); return false; }); // スクロールが200に達したらボタン表示 $(window).scroll(function(){ if( $(this).scrollTop() > 200 ) $btn.addClass('show'); else $btn.removeClass('show'); }); }); return this; }; // -------------------------------------------------------------------- // SP客室紹介スライドショー // -------------------------------------------------------------------- jQuery.fn.stwPhotoSlider = function(){ // PC if( window.innerWidth > 640 ) return this; // SP this.each(function(){ var $this = $(this); if( $this.children().length < 3 ) return; $this.slick({ centerMode: true, centerPadding: '50px', //variableWidth: true, slidesToShow: 1, dots: false, infinite: true, arrows: false }); // 左右の余白20pxを消す // css の calc() でもできるがAndroid4.0標準ブラウザで効かないので $this.css({ width: $this.parent().outerWidth(), left: -10 }); // 高さが異なるスライド上下中央に調整 //$(window).load(function(){ // var H = $this.height(); // $this.find('.slick-slide').each(function(){ // if( $(this).find('p').length ) return; // テキストある時は調整しない // var dH = H - $(this).height(); // if( dH > 0 ) $(this).css({ top: dH / 2 }); // }); //}); }); return this; }; // -------------------------------------------------------------------- // ツアー有無確認 // -------------------------------------------------------------------- jQuery.fn.stwTourCheck = function(){ // クエリ集める var queries = {}; this.each(function(){ var $this = $(this); queries[$this.attr('data-query')] = true; }); // クエリ毎に $.each(queries, function( query ){ var $links = $('[data-query="'+ query +'"] > a'); // PC/SP判定 var isSP = $('.breadcrumb.sp_only').is(':visible'); // ボタンリンクURL if( isSP ){ $links.attr({ href: '//i.stworld.jp/tour/maldives?' + query, target: '_blank' }); } else{ $links.attr({ href: '//stworld.jp/tour_search_f2/#/?homenG=IO&homen=MV&' + query, target: '_blank' }); } // ツアー無かったら問い合わせフォームリンクに $.get('/feature/MV/tour_search.php?homenG=IO&homen=MV&' + query, function(data){ if( data.resnum <= 0 ){ $links.attr({ //href: 'https://secure.stworld.jp/form/?cu=MV', href: 'https://secure.stworld.jp/form_estimate/', target: '_blank' }); $links.text('お問い合わせ'); } }); }); return this; }; $(function(){ // SPページトップ $('.sp_pagetop').stwPageTop(); // SP客室紹介スライドショー $('.siteBoxInner.photo.bg_Yellow').each(function(){ var $this = $(this); $this.children('ul.img02').stwPhotoSlider(); $this.children('ul.img03').stwPhotoSlider(); $this.children('ul.img04').stwPhotoSlider(); }); // ツアー有無確認 $('[data-query]').stwTourCheck(); });