我在这里遇到了一个小问题。我对Javascript有基本的了解,想要做以下事情:
现在,当你向下滚动时,菜单会变小。当你向上滚动时,它会恢复正常大小。我使用window.onscroll来调用这个事件:
var diff = 0;
function effects(){
var topDistance = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
var clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
if(topDistance > diff){
diff = topDistance;
if(clientWidth > 1024){
if(topDistance > 300){
document.getElementById("header").style.marginTop= "-100px";
}
}
}else if(topDistance < diff){
diff = topDistance;
if(clientWidth > 1024){
if(topDistance > 300){
document.getElementById("header").style.marginTop= "0";
}
}
}
}
window.onscroll = effects();
现在我想要另一个函数来影响我的CTA按钮,我们称之为“test”,但如果我想像上面那样做,那么特效函数将不再起作用:
function test(){
//do something
}
window.onscroll = test();
欢迎任何帮助!我觉得这不会是一个很大的挑战,但我猜我做错了。(注:请勿使用jQuery)
effects
样式设计标题和test
样式设计一些按钮,但两者都执行相同的滚动/偏移高度检查? - nem035