0

ヘッダーの高さ/位置が他のページ (ページ X および Y) とは異なる小さなサイトを設計しています。.animate を使用して、ユーザーがインデックスからページ X または Y に移動した場合にのみスタイルの変更をアニメーション化したいのですが、ユーザーがページ X と Y の間を移動した場合はそうではありません。

Jquery を使用してユーザーがどのページにいるかを判断し、ユーザーがインデックスから X または Y に移動している場合にのみアニメーションを開始するにはどうすればよいですか?

CSS、ヘッダー:

header {
width: 100%;
padding: 4% 0 10px;
}

インデックス ヘッダー:

.index header {
position: absolute;
top: 130px;
} 

X & Y ヘッダー:

.work header, .bio header {
padding-top: 2%;
}
4

2 に答える 2

0

リファラーを使用して元のページを特定し、インデックスから来ている場合は、X または Y にのみ存在する要素の存在を確認します。

$(document).ready(function() {
   var referrer =  document.referrer;
   if(/*do custom check on referrer to see if you are coming from index */)
   {   
       // to check if you are on X or Y
       if($(".work").length || $(".work").length){
           // trigger animation 
       }
   }

});
于 2013-04-09T04:57:27.420 に答える
0

試す

$(function() {
    if (/index.html/.test(document.referrer)) { //Use your index page url in the regex instead of index.html
        //do your animation
    }
});
于 2013-04-09T05:10:02.803 に答える