/* * jQuery smoothAnchor * * jQuery required. * jQuery Easing Plugin extends this Plugin. * * Copyright 2009 (c) kamem * http://develo.org/ * Licensed Under the MIT. * * Date: 2010.09.4 */ //例 : $('h1').smoothAnchor({easing : 'quart',speed : 1000,target : #header}); //アンカーがないときになにもtarget指定がなかった場合の飛び先 var target = '#header'; $(function() { //(動き,スピード,ターゲット(#headerなど)) $('a[href^="#"]').smoothAnchor({easing : 'easeOutQuart',speed : 1000}); /*画面クリック時アニメーションを止める var pageWrapTag = $.support.boxModel ? navigator.appName.match(/Opera/) ? "html" : "html,body" : "body"; $(document).click(function(){ $(pageWrapTag).queue([]).stop() });*/ //アドレスに#1000,10など数値で指定している場合その位置に移動 if(parseInt(location.hash.slice(1))) { var targetAddress = location.hash.split(","); var targetPositiontop = parseInt(targetAddress[1]); var targetPositionleft = parseInt(targetAddress[0].slice(1)); //boxModelによって実装が違うみたいでたとえば、後方互換モードは body、Operaは html,body の両方指定にすると、不具合が出る var pageWrapTag = $.support.boxModel ? navigator.appName.match(/Opera/) ? "html" : "html,body" : "body"; $(pageWrapTag).animate({ scrollTop : targetPositiontop,scrollLeft : targetPositionleft }, 0, 0); } }); //jQuery Plugin $.fn.smoothAnchor = function(options) { var c = $.extend({ easing: '', speed: '', target: target },options); tagClick($(this),c.easing,c.speed,c.target); } //タグをクリックしたとき function tagClick(tag,easing,speed,target) { tag.click(function () { //タグにアンカーがない指定したアンカー(target)を入れる target = (this.hash) ? target = this.hash : target; var tag = this; smoothAnchor({tag: tag,easing: easing,speed: speed,target: target}); return false; }); } //処理 function smoothAnchor(options) { //初期設定 var c = $.extend({ tag: 'body', easing: 'easeOutQuart', speed: 1000, target: target },options); tag = c.tag easing = c.easing; speed = c.speed; target = c.target; //boxModelによって実装が違うみたいでたとえば、後方互換モードは body、Operaは html,body の両方指定にすると、不具合が出る var pageWrapTag = $.support.boxModel ? navigator.appName.match(/Opera/) ? "html" : "html,body" : "body"; $(pageWrapTag).queue([]).stop(); //数字ターゲットの場合 数字の位置に移動(例 : #1000,10) if(parseInt(target.slice(1))) { target = target.split(","); var targetPositiontop = parseInt(target[1]); var targetPositionleft = parseInt(target[0].slice(1)); } //普通の場合 else { var targetPosition = $(target).offset(); var targetPositiontop = targetPosition.top; var targetPositionleft = targetPosition.left; } $(pageWrapTag).animate({ scrollTop : targetPositiontop,scrollLeft : targetPositionleft }, speed, easing,function(){location.hash = target }); //アンカー一から、少しずらしたいときは↓を使ってください。アドレスバーはかわりません。 //$("html,body").animate({ scrollTop: targetPosition - 100 }, 1000, 'quart'); } /* * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/ * * Uses the built in easing capabilities added In jQuery 1.1 * to offer multiple easing options * * TERMS OF USE - jQuery Easing * * Open source under the BSD License. * * Copyright %copy; 2008 George McGinley Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * Neither the name of the author nor the names of contributors may be used to endorse * or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */ jQuery.easing.jswing=jQuery.easing.swing; jQuery.easing.jswing=jQuery.easing.swing; jQuery.extend(jQuery.easing,{ def:"easeOutQuad", swing:function(j,i,b,c,d){return jQuery.easing[jQuery.easing.def](j,i,b,c,d);},easeInQuad:function(j,i,b,c,d){return c*(i/=d)*i+b;},easeOutQuad:function(j,i,b,c,d){return -c*(i/=d)*(i-2)+b;}, easeInOutQuad:function(j,i,b,c,d){if((i/=d/2)<1){return c/2*i*i+b;}return -c/2*((--i)*(i-2)-1)+b;},easeInCubic:function(j,i,b,c,d){return c*(i/=d)*i*i+b;},easeOutCubic:function(j,i,b,c,d){return c*((i=i/d-1)*i*i+1)+b;},easeInOutCubic:function(j,i,b,c,d){if((i/=d/2)<1){return c/2*i*i*i+b;}return c/2*((i-=2)*i*i+2)+b;}, easeInQuart:function(j,i,b,c,d){return c*(i/=d)*i*i*i+b;}, easeOutQuart:function(j,i,b,c,d){return -c*((i=i/d-1)*i*i*i-1)+b;}, easeInOutQuart:function(j,i,b,c,d){if((i/=d/2)<1){return c/2*i*i*i*i+b;}return -c/2*((i-=2)*i*i*i-2)+b;}, easeInQuint:function(j,i,b,c,d){return c*(i/=d)*i*i*i*i+b;}, easeOutQuint:function(j,i,b,c,d){return c*((i=i/d-1)*i*i*i*i+1)+b;}, easeInOutQuint:function(j,i,b,c,d){if((i/=d/2)<1){return c/2*i*i*i*i*i+b;}return c/2*((i-=2)*i*i*i*i+2)+b;}, easeInSine:function(j,i,b,c,d){return -c*Math.cos(i/d*(Math.PI/2))+c+b;}, easeOutSine:function(j,i,b,c,d){return c*Math.sin(i/d*(Math.PI/2))+b;}, easeInOutSine:function(j,i,b,c,d){return -c/2*(Math.cos(Math.PI*i/d)-1)+b;}, easeInExpo:function(j,i,b,c,d){return(i==0)?b:c*Math.pow(2,10*(i/d-1))+b;}, easeOutExpo:function(j,i,b,c,d){return(i==d)?b+c:c*(-Math.pow(2,-10*i/d)+1)+b;}, easeInOutExpo:function(j,i,b,c,d){if(i==0){return b;}if(i==d){return b+c;}if((i/=d/2)<1){return c/2*Math.pow(2,10*(i-1))+b;}return c/2*(-Math.pow(2,-10*--i)+2)+b;},easeInCirc:function(j,i,b,c,d){return -c*(Math.sqrt(1-(i/=d)*i)-1)+b;}, easeOutCirc:function(j,i,b,c,d){return c*Math.sqrt(1-(i=i/d-1)*i)+b;}, easeInOutCirc:function(j,i,b,c,d){if((i/=d/2)<1){return -c/2*(Math.sqrt(1-i*i)-1)+b;}return c/2*(Math.sqrt(1-(i-=2)*i)+1)+b;}, easeInElastic:function(o,m,p,a,b){var d=1.70158;var c=0;var n=a;if(m==0){return p;}if((m/=b)==1){return p+a;}if(!c){c=b*0.3;}if(n