Skip to content

Instantly share code, notes, and snippets.

@akkijp
Last active October 29, 2015 16:35
Show Gist options
  • Save akkijp/c1c31c04bf6552d55cc2 to your computer and use it in GitHub Desktop.
Save akkijp/c1c31c04bf6552d55cc2 to your computer and use it in GitHub Desktop.
jQueryを使ったいろいろなエフェクト あれそれ

jQueryを使ったいろいろなエフェクト あれそれ

クラス名「slide_page_handler」がクリックされた時に、 ページ全体が横にスライドするエフェクトを追加する。

$("body > *").wrapAll('<div id="slide_page_wrapper" style="width:100%"></div>');
$('.slide_page_handler').click(function(){
  var pass = $(this).attr("href");
  $('#slide_page_wrapper').animate({marginLeft: '-='+$(window).width()+'px'},300,function(){
    location.href = pass;
  });
  return false;
});

ヘッダーがあって、idを使ってページ移動をする際は位置ずれを起こすので、 それを解決し、スクロールを行うスクリプト ページ内に存在するすべてのidリンクに作用する

$(function () {
  var headerHight = 110; //ヘッダーの高さ
    $('a[href^=#]').click(function(){
    var href= $(this).attr("href");
    var target = $(href == "#" || href == "" ? 'html' : href);
    var position = target.offset().top - headerHight;
    $("html, body").animate({scrollTop:position}, 550, "swing");
    return false;
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment