Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23594
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Mattias Campe <mattiaspuntcampe@geeeemeil.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: jQuery: fadeIn/out + count |
| Date | Thu, 13 Mar 2014 20:31:09 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 61 |
| Message-ID | <lft11t$adj$1@dont-email.me> (permalink) |
| References | <lfptbf$b5m$1@dont-email.me> <53210464$0$6672$9b4e6d93@newsspool2.arcor-online.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 13 Mar 2014 19:31:09 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="4f01d133ad3a9401e163c12e689a43fe"; logging-data="10675"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RP59AC+0Q7jdm9CrZgAcz" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
| In-Reply-To | <53210464$0$6672$9b4e6d93@newsspool2.arcor-online.net> |
| Cancel-Lock | sha1:cBwx2mml8QocApPgjtNcEnKGA9E= |
| Xref | csiph.com comp.lang.javascript:23594 |
Show key headers only | View raw
op 13-03-14 02:05, Christoph Michael Becker schreef:
> Mattias Campe wrote:
>
>> I got multiple paragraphs and some of them need to have a fadeIn, some a
>> fadeOut. After that code I want to count the paragraphs that are still
>> visible.
>>
>> The fadeIn or fadeOut works as I expect, but not the counting. I guess
>> that is because the animation is still busy, while the counting already
>> starts. A kind of "parallel" processing.
>>
>> Would anybody know if that is the cause and/or a solution for my problem?
>
> Indeed, the "parallel processing" is the cause of your problem. The
> fadeIn() and fadeOut() methods trigger an animation (the implementation
> might use window.setInterval() or window.setTimeout()), which is
> obviously not finished when you access the length property.
>
> A solution might be to do the count "manually" in the if-else statement.
> An alternative would be to delay the counting until the animation has
> finished.
>
>> if (jQuery('input#' + geg).is(":checked")){
>> jQuery("p." + geg).fadeIn();
>> } else {
>> jQuery("p." + geg).fadeOut();
>> }
>>
>> var nSr = eval(jQuery('p.sr:visible').length); // BUG?
>
> The behavior is not a bug (maybe a documentation bug for the
> fadeIn()/fadeOut() methods), but your use of eval() is superfluous at best.
I didn't mean it as a bug in JavaScript or jQuery, but it didn't work
the way I was "hoping" it to work. So the fault is all mine.
I solved it by doing a "jQuery('p.sr:visible').length;" before any
animation and per fadeIn I do a nSr++ and per fadeOut a nSr--, in the
if-else statement. That seems to work, so thank you for the tip. And I
have omitted the eval().
> Please note that this newsgroup might not be the best place to ask
> questions related to jQuery, as the newsgroup's FAQ states[1]:
>
> | No javascript libraries are endorsed by this group. If you want help
> | with using a library, visit that library's discussion group instead.
>
> IMHO it is best to avoid libraries like jQuery until you have a good
> understanding of ECMAScript and the DOM and their (widespread)
> implementations, so you can judge the value of such libraries.
>
> [1] <http://pointedears.de/scripts/faq/cljs/#libraryResources>
>
I didn't notice that FAQ. I should indeed invest some time to have a
good understanding of it. But I was already happy to "assume" it might
be because of "the parallel processing" :-). And sometimes the proof of
the pudding is in the eating :-).
Kind regards
Mattias
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
jQuery: fadeIn/out + count Mattias Campe <mattiaspuntcampe@geeeemeil.com> - 2014-03-12 16:09 +0100
Re: jQuery: fadeIn/out + count Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-03-12 17:50 +0100
Re: jQuery: fadeIn/out + count Mattias Campe <mattiaspuntcampe@geeeemeil.com> - 2014-03-12 21:17 +0100
Re: jQuery: fadeIn/out + count Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-12 18:04 -0300
Re: jQuery: fadeIn/out + count Mattias Campe <mattiaspuntcampe@geeeemeil.com> - 2014-03-13 20:22 +0100
Re: jQuery: fadeIn/out + count Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-13 02:05 +0100
Re: jQuery: fadeIn/out + count Mattias Campe <mattiaspuntcampe@geeeemeil.com> - 2014-03-13 20:31 +0100
csiph-web