Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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
Jquery 当用户在+;y轴和-y轴?_Jquery_Html_Css_Svg - Fatal编程技术网

Jquery 当用户在+;y轴和-y轴?

Jquery 当用户在+;y轴和-y轴?,jquery,html,css,svg,Jquery,Html,Css,Svg,下面是我为SVG编写的代码。每当用户滚动时,我都试图操纵ID#temp的height属性 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"viewBox="0 0 25.25 104" enable-background="new 0 0 25.25 104" xml:space="pres

下面是我为SVG编写的代码。每当用户滚动时,我都试图操纵ID#temp的height属性

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"viewBox="0 0 25.25 104" enable-background="new 0 0 25.25 104" xml:space="preserve">
  <rect  id="temp" width="10"  style="fill:rgb(0,0,255);" transform="rotate(180,5,2)" x="-7" y="-100">
   <!-- <animate attributeName="height" from="0" to="95" dur="3s"/> --> 
  </rect>


<path id="thermo" d="M15.8,0H9.2C4.679,0,1,3.678,1,8.199V95.8c0,4.521,3.679,8.2,8.2,8.2h6.6c4.521,0,8.23.679,8.2-8.2V8.199
C24,3.678,20.321,0,15.8,0z M22,95.8c0,3.419-2.781,6.2-6.2,6.2H9.2C5.781,102,3,99.219,3,95.8V84.5h8.25v-2H3v-6.357h8.25v-2H3
v-6.357h8.25v-2H3v-6.356h8.25v-2H3v-6.357h8.25v-2H3v-6.357h8.25v-2H3v-6.357h8.25v 2H3V26h8.25v-2H3V8.199C3,4.781,5.781,2,9.2,2
 h6.6C19.219,2,22,4.781,22,8.199V95.8z"> 
</path>

问题是您正在将变量
initHeight
设置为看起来像函数的值,然后将其作为函数调用,但它不是函数。要像函数一样使用它,您需要这样声明它:

var initHeight = function(){ $("#temp").attr("height", 5); }
我还为起始数字5声明了一个变量。在滚动事件中,递增
newHeight
,然后将高度设置为此新数字

var newHeight = 5;

$(document).on('scroll', function(){
    newHeight += 1;
    $("#temp").attr("height", newHeight);
});
您还可以在
attr
调用中按如下方式递增:
++newHeight
在设置之前递增它。使用
newHeight++
将设置高度,然后增加它


Brouxhaha!非常感谢您对此进行调查,并如此简单地回答我的问题!
var newHeight = 5;

$(document).on('scroll', function(){
    newHeight += 1;
    $("#temp").attr("height", newHeight);
});