Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将图像从屏幕中间移动到滚动的角落_Javascript_Html_Css - Fatal编程技术网

Javascript 将图像从屏幕中间移动到滚动的角落

Javascript 将图像从屏幕中间移动到滚动的角落,javascript,html,css,Javascript,Html,Css,嘿,我是个新手,所以请原谅我犯的任何明显错误,谢谢:) 因此,每当你开始滚动时,我需要一个图像从屏幕中间移动到屏幕的角落。我能走这么远。唯一的问题是,当我滚动回到顶部时,图像不会回到原始位置 感谢您提前提供的帮助:) window.onscroll=function(){scrollFunction()}; 函数滚动函数(){ 如果(document.body.scrollTop>50 | | document.documentElement.scrollTop>50){ document.g

嘿,我是个新手,所以请原谅我犯的任何明显错误,谢谢:)

因此,每当你开始滚动时,我需要一个图像从屏幕中间移动到屏幕的角落。我能走这么远。唯一的问题是,当我滚动回到顶部时,图像不会回到原始位置

感谢您提前提供的帮助:)

window.onscroll=function(){scrollFunction()};
函数滚动函数(){
如果(document.body.scrollTop>50 | | document.documentElement.scrollTop>50){
document.getElementById(“logo”).style.width=“70px”;
document.getElementById(“logo”).style.margin=“0px”;
document.getElementById(“徽标”).style.position=“固定”;
}否则{
document.getElementById(“logo”).style.width=“30%”;
document.getElementById(“徽标”).style.margin=“0自动”;
document.getElementById(“logo”).style.position=“relative”;
}
}
#徽标{
宽度:30%;
过渡:0.5s;
保证金:0自动;
利润率最高:15%;
}
.卷轴{
高度:1200px;
}

所以问题是,当您向上滚动时,您没有添加
边距

这可以通过使用javascript添加或重新添加边距来简单地解决

window.onscroll=function(){scrollFunction()};
函数滚动函数(){
如果(document.body.scrollTop>50 | | document.documentElement.scrollTop>50){
document.getElementById(“logo”).style.width=“70px”;
document.getElementById(“logo”).style.margin=“0px”;
document.getElementById(“徽标”).style.position=“固定”;
}否则{
document.getElementById(“logo”).style.width=“30%”;
document.getElementById(“徽标”).style.margin=“0自动”;
document.getElementById(“logo”).style.marginTop=“15%”;
document.getElementById(“logo”).style.position=“relative”;
}
}
#徽标{
宽度:30%;
过渡:0.5s;
保证金:0自动;
利润率最高:15%;
}
.卷轴{
高度:1200px;
}

当我测试它时,它似乎工作正常。。。不确定是什么问题?