Jquery .animate只从索引页



我正在设计一个小网站,其中页眉将有不同的高度/位置比其他页面(页X &我想使用。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%;
}

使用referrer确定您来自的页面,如果您来自index,则检查是否存在仅在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 
       }
   }
});

Try

$(function() {
    if (/index.html/.test(document.referrer)) { //Use your index page url in the regex instead of index.html
        //do your animation
    }
});

最新更新