简体   繁体   English

将JQuery .css放入条件语句

[英]Putting JQuery .css into conditional statement

Ok, so I've made a timer that makes parts of my SVG map fadeOut as they cross certain thresholds. 好的,所以我做了一个计时器,使SVG贴图的某些部分超过某些阈值时它们就会淡出。 However, I want to mess with other parts of the CSS. 但是,我想弄乱CSS的其他部分。

I looked at this post, but couldn't make sense of it in terms of my problem. 我看了这篇文章,但就我的问题而言,却无法理解。

** Edits Below** **编辑如下**

Thanks for the help, I took a look at my code and tried to clean out some of the stuff that didn't need to be there. 感谢您的帮助,我看了一下我的代码,并尝试清除一些不需要的代码。 I also restructured my if statement, putting it inside of the JQuery code. 我还重组了if语句,将其放在JQuery代码中。 I tried the suggestion below, assigning the var timer outside the interval function, but then my start button no longer worked and the script started running on page load. 我尝试了以下建议,在interval函数之外分配了var计时器,但随后我的开始按钮不再起作用,脚本在页面加载时开始运行。 So, I moved it back to keep things working. 因此,我将其移回以保持工作状态。 Also, put my code into JSFiddle, but I couldn't get it to work correctly. 另外,将我的代码放入JSFiddle,但我无法使其正常工作。 Will spend some more time familiarizing myself with that in the meantime. 在此期间,将花费更多时间来熟悉自己。 Thank you for introducing me to that. 谢谢您向我介绍。

As for my original question: the .animate() tag works so long as I set it to change the opacity attribute, but has no effect on the other attributes I want to change. 至于我最初的问题:.animate()标记只要设置为更改opacity属性即可起作用,但对我要更改的其他属性没有影响。 I know SVG and CSS have different attribute names, and I've tried both types of names. 我知道SVG和CSS具有不同的属性名称,并且我尝试了两种类型的名称。 Here is my code below. 这是下面的代码。 I am trying to get the .animate() effect to change the fill color and stroke-width. 我试图获得.animate()效果来更改填充颜色和笔触宽度。

var i,timer;
i = 2013;

function start() {
timer = self.setInterval("increment()", 800 )
}

function increment() {
i++;
document.getElementById("timer_out").innerHTML =  i ;
$(document).ready( function() {
    if (i == 2014) {
        $('#AL').animate( {
            opacity: 0.3 } , 500 );
    }
});
}

function stop() {
clearInterval(timer);
timer = null;
 }

function reset() {
stop();
i=2013;
document.getElementById("timer_out").innerHTML = i;
}

I'm really just concerned with the JQuery statement, which works perfectly fine until I replace opacity with a different CSS attribute. 我真的只关心JQuery语句,该语句工作得很好,直到我将opacity替换为其他CSS属性为止。

Thanks again for the attention and advice. 再次感谢您的关注和建议。

1) if you divide any number by 1 you get the original number, your divisions are doing nothing as far as i can tell. 1)如果将任何数字除以1,就得到原始数字,就我所知,您的除法没有任何作用。

2) setInterval should be written: 2)setInterval应该写为:

timer = setInterval(increment, ( 1000 / divide ))

also note increment() and start() are not good name choices to have in global scope, how many people will think of those names, use anonymous functions maybe to contain scope 还请注意,在全局范围内,increment()和start()并不是很好的名称选择,有多少人会想到这些名称,使用匿名函数可能包含范围

(function()
{
  // function is now contained within anonymous function scope and not accessible outside
  function increment(){} 
})()

3) logically step though your code in your head. 3)在逻辑上跨过您的代码。 your code wont work 您的代码无法正常工作

4) create a fiddle of what you have done so far 4)创建到目前为止所做的小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM