Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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_Jquery_Html_Css - Fatal编程技术网

Javascript 如何使固定的背景图像不固定在滚动条上?

Javascript 如何使固定的背景图像不固定在滚动条上?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,是的,这个标题可能让人困惑,但原因如下 我有一个捐款柜台,我想在一个侧边栏导航下的网站上使用。问题是,我创建捐赠计数器的方式是使用带有固定背景图像的代码笔。愚蠢的我没有考虑到如果有人滚动整件东西就要去了,我很新的编码,所以不知道一个更好的方法。这是我的代码和一个JSFIDLE,如果没有任何关于如何在不使用背景图像的情况下创建它的建议,有没有人对我如何解决问题有什么想法 (我添加了文本以便您可以滚动) jquery percent = $('#bar div span').html(); tota

是的,这个标题可能让人困惑,但原因如下

我有一个捐款柜台,我想在一个侧边栏导航下的网站上使用。问题是,我创建捐赠计数器的方式是使用带有固定背景图像的代码笔。愚蠢的我没有考虑到如果有人滚动整件东西就要去了,我很新的编码,所以不知道一个更好的方法。这是我的代码和一个JSFIDLE,如果没有任何关于如何在不使用背景图像的情况下创建它的建议,有没有人对我如何解决问题有什么想法

(我添加了文本以便您可以滚动)

jquery

percent = $('#bar div span').html();
total = $('#bar').attr('data-total');
percentStart = 0;

setInterval(function() {
$('.show').css('height',percentStart/total*100+'%');
$('#bar').css('height',percentStart/total*100+'%');
$('#bar div span').html('%'+percentStart);
if(percentStart<percent) {percentStart=percentStart+1;}
},35);

$("#bar div").addClass("load");
percent=$('#bar div span').html();
总计=$('#bar').attr('data-total');
百分比开始=0;
setInterval(函数(){
$('.show').css('height',percentStart/total*100+'%');
$('#bar').css('height',percentStart/total*100+'%');
$('#bar div span').html('%'+percentStart);

如果
.container
的css中有(percentStart,则更改

position:relative

然后相应地调整
顶部
左侧


只需将背景位置设置为左侧和底部:

并从背景中删除了“固定”

background: url(http://fdfranklin.com/usf-bull-bw.png) left bottom

那把小提琴不适合我。。。
position:relative
position:fixed
background: url(http://fdfranklin.com/usf-bull-bw.png) left bottom