Hi all,
I enjoyed our meeting today and it was great to see everyone!
In the discussions during Seth's "Intro to jQuery" presentation at tonight's
meeting, we got into a discussion regarding the ability to split single
jQuery commands over multiple lines.
The example that was given was related to a chaining event, so you could
have the following single line in jQuery:
$('#something').addClass('someClass').show(1000).hide(1000).show(1000);
broken out into this equivalent and possibly more legible:
$('#something')
.addClass('someClass')
.show(1000)
.hide(1000)
.show(1000);
The question was asked regarding the ability to place "normal" JavaScript
over multiple lines like the above jQuery example.
I am not a very creative type so I came up with this rather bland code that
breaks out several different types of "normal" JavaScript code over several
lines and it all still works.
I am not sure that this is a better way to format JS code, but it certainly
opens doors if you were unaware that you could break JS out over multiple
lines.
<html>
<head>
<script>
function firstFunction()
{
var myResult = '';
myResult = secondFunction(
document.getElementById('FirstVar').value
, document
.getElementById('SecondVar')
.value
);
alert(myResult);
}
function secondFunction( myFirstVar, mySecondVar )
{
var myReturnVar = '';
myReturnVar = '( '
+ myFirstVar
+ ' * '
+ mySecondVar
+ ' ) = '
+ (myFirstVar*mySecondVar);
return myReturnVar;
}
</script>
</head>
<body>
<form>
<input id="FirstVar" />
*
<input id="SecondVar" />
=
<input type="button" onClick="firstFunction();" />
</form>
</body>
</html>
Also, I asked a question about how chaining worked on FadeIn and those types
of calls, as they have their own callback methods, so it seemed like there
must have been something special about how those are handled.
After reading a few posts online, it appears that these types of calls are
handled a little differently in that they have to use things like setTimeout
to make their magic work.
So if you had
$('#something').FadeIn(10000).addClass('someClass');
This would find the ID of "something" and start the process of adding a
FadeIn affect, then add the class "someClass" without actually waiting for
the FadeIn to finish first.
If you need to have the FadeIn process finish before the next thing is
called, the FadeIn function has callback parameter and you could use it like
this:
$('#something').FadeIn(10000, function () { addClass('someClass') } );
Then if you needed to chain addiitonal elements, they would go inside the
anonymous function:
$('#something').FadeIn(10000, function () {
addClass('someClass').addClass('someOtherClass') } );
Also, we discussed the different values that can be used for the speed
parameter to functions like show, hide, fadein, etc. I gave incorrect
information during our discussion;
There are actually 3 valid string speeds ("slow", "def", or "fast") or you
can use a number value in milliseconds. Any string value other than the
ones listed will be treated the same as "def" (400ms).
Anyway I hope these little notes help someone!
Thanks again Seth for a great presentation!
--
Ken Auenson
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Houston ColdFusion
Users' Group" discussion list.
To unsubscribe, send email to [email protected]
For more options, visit http://groups.google.com/group/houcfug?hl=en
-~----------~----~----~----~------~----~------~--~---