Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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
Html 在导航栏中滚动显示不同的图像_Html_Css_Twitter Bootstrap - Fatal编程技术网

Html 在导航栏中滚动显示不同的图像

Html 在导航栏中滚动显示不同的图像,html,css,twitter-bootstrap,Html,Css,Twitter Bootstrap,我想在向下滚动时更改navbar(在img src=)中显示的图像。但是,该图像不在css类中,因此我不确定如何实现。你能建议解决这个问题的最佳方法吗?我应该把图像放在css类中吗 访问img元素的DOM对象,并更改src属性以更新图像 (函数(win、doc、未定义){ var imgEl=document.querySelector(“#header img”), 下一步http://placehold.it/1200x100/', 切换=假; 函数onScroll(e){ img

我想在向下滚动时更改navbar(在img src=)中显示的图像。但是,该图像不在css类中,因此我不确定如何实现。你能建议解决这个问题的最佳方法吗?我应该把图像放在css类中吗



访问
img
元素的DOM对象,并更改
src
属性以更新图像

(函数(win、doc、未定义){
var imgEl=document.querySelector(“#header img”),
下一步http://placehold.it/1200x100/',
切换=假;
函数onScroll(e){
imgEl.src=nextSrc;
win.removeEventListener('scroll',onScroll);
}
win.addEventListener('scroll',onScroll);
}(window,window.document))
正文{
保证金:0;
最小高度:125vh;
}


您可以更改img src。非常感谢。它起作用了,但是有一个bug-imgEl没有在onScroll函数中定义。你一定没有像我上面那样实现
imgEl
是在
onScroll
的定义之外定义的,所以
imgEl
onScroll
内部可用。嗯,是的,我可能犯了一个错误