<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cherrysave &#187; JQuery</title>
	<atom:link href="http://www.cherrysave.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cherrysave.com</link>
	<description>A simple web design blog</description>
	<lastBuildDate>Tue, 22 Jun 2010 23:53:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>JQuery for Beginners: Using Simple JQuery Effects for a Rockstar User Interface</title>
		<link>http://www.cherrysave.com/jquery/jquery-for-beginners-using-simple-jquery-effects-for-a-rockstar-user-interface/</link>
		<comments>http://www.cherrysave.com/jquery/jquery-for-beginners-using-simple-jquery-effects-for-a-rockstar-user-interface/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:30:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.cherrysave.com/?p=254</guid>
		<description><![CDATA[JQuery is a Javascript library that attempts to make things like editing styles, creating animations, and using AJAX much easier than it has been in the past. Let's be honest: Javascript can very occasionally be a nasty code to program with, and JQuery attempts to tone it down a little bit and make it much more manageable.]]></description>
			<content:encoded><![CDATA[<p>JQuery is a Javascript library that attempts to make things like editing styles, creating animations, and using AJAX much easier than it has been in the past. Let's be honest: Javascript can very occasionally be a nasty code to program with, and JQuery attempts to tone it down a little bit and make it much more manageable.</p><p><a href="http://api.tweetmeme.com/share?url=http://www.cherrysave.com/jquery/jquery-for-beginners-using-simple-jquery-effects-for-a-rockstar-user-interface/"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://www.cherrysave.com/jquery/jquery-for-beginners-using-simple-jquery-effects-for-a-rockstar-user-interface/" height="61" width="51" /></a></p><p>This is the second part of my series on JQuery for Beginners. Be sure to check out the <a href="http://www.cherrysave.com/programming/jquery-for-beginners-selectors-hierarchies-and-attributes-oh-my/">first part of the JQuery tutorial series</a> where I introduce the framework and show readers show to use selectors, hierarchies, and attributes.</p>
<h3>Simple Effects</h3>
<p>One of my favorite parts about the JQuery library is the built-in effects, which can be tied into the events manager to animate the appearance and disappearance of elements in the web page. That is, you can make things like <code>div</code> and <code>a</code> elements slide or fade with ease.</p>
<p>So, the first thing we need to do is create a link and a paragraph to play with. My goal is to make the paragraph do things (i.e. slide and fade) when users click on the link. The most important thing is use fill in the id attribute of the paragraph and the link. Without it, JQuery won&#8217;t as easily know which elements we are referring to.</p>
<pre>
&lt;p id=&quot;paragraph&quot;&gt;This is the demonstration paragraph.&lt;/p&gt;
&lt;a href=&quot;#&quot; id=&quot;link&quot;&gt;Click this to do things!&lt;/a&gt;
</pre>
<p>Now, we&#8217;ll get started with the JQuery. First, we want to declare a function that runs right when the page loads. We do that with <code>$(document).ready</code>. After that, we need to select the link and drop it into a function. We call the link with <code>$("#link")</code>, and make it react to <code>click</code>. Then, we select the paragraph, and do something with it. Here, we&#8217;ll hide it. Here&#8217;s the source code:</p>
<pre>
$(document).ready(function(){
    $(&quot;#link&quot;).click(function () {
      $(&quot;#paragraph&quot;).hide();
    });
  });
</pre>
<h3>Slides, Fades, and Toggling</h3>
<p>As soon as the page loads, JQuery finds the link and attaches an action to it when the link is clicked. That action, located inside the function, will <b>hide</b> the paragraph called <code>#paragraph</code>. Using the same format, you can swap in a whole variety of effects using the same pattern. For instance, you can make the paragraph fade out with the <code>fadeOut</code> method. Here&#8217;s some good ol&#8217; source code for you:</p>
<pre>
$(document).ready(function(){
    $(&quot;#link&quot;).click(function () {
      $(&quot;#paragraph&quot;).fadeOut();
    });
  });
</pre>
<p>Here&#8217;s the full list of effects you can use like this:</p>
<ul>
<li>show</li>
<li>hide</li>
<li>toggle</li>
<li>slideDown</li>
<li>slideUp</li>
<li>slideToggle</li>
<li>fadeIn</li>
<li>fadeOut</li>
</ul>
<h3>Speed and Callbacks</h3>
<p>But you want more fine-tuned control, don&#8217;t you? Well, you can do two more things with these effects methods. First, you can pass a first argument that controls the <b>speed</b> of the animation. This can use one of three predefined speeds (such as <code>slow</code>, <code>normal</code>, and <code>fast</code>) or a speed defined in milliseconds (134 milliseconds, and not a millisecond more). The other thing you can do is add a callback. A callback is a function that will be called as soon as the effect is complete. For instance, you can make a fast fade out that alerts you when it is done:</p>
<pre>
$(document).ready(function(){
    $(&quot;#link&quot;).click(function () {
      $(&quot;#paragraph&quot;).fadeOut(&quot;slow&quot;, function () {
         alert(&quot;I'm done!&quot;);
    });
    });
  });
</pre>
<h3>Custom Effects</h3>
<p>So you want to add a little bit more customization that you have with the built-in effects? Well, then it&#8217;s time to make a custom animation. I&#8217;m going to omit the <code>ready</code> and the <code>click</code> function, so refer to the code samples above if you are still murky on the idea. In general, the custom animation method takes the following form:</p>
<pre>
$(&quot;#paragraph&quot;).animate({width: 50%, opacity: 0.5}, &quot;slow&quot;, &quot;swing&quot;);
</pre>
<p>The first attribute in the brackets is a series of styles you want to animate to. These are based on CSS. In my example, I&#8217;m going to increase the size of the paragraph by 50 percent and I&#8217;m going to half the opacity. The next parameter is the duration; here, I&#8217;m going to resize and dim slowly. The last parameter is easing. Easing, in a nutshell, controls the evenness of the animation. <code>linear</code> will make it the same speed the entire time. <code>swing</code> will make the animation faster toward the end. You can also include an optional callback as the last function.</p>
<h3>I Hate Animations</h3>
<p>One problem is that animations tend to destroy the notion of simple web design. Yes, they can add a more natural feel to the UI, but they can also make things a bit too flashy for a minimalist. Therefore, you may want to give users the option of disabling all animations. Anytime the following method is called, all animations will cease to work.</p>
<pre>
jQuery.fx.off = true;
</pre>
<p>Of course, you can turn it back on by setting it to <code>false</code>.</p>
<h3>Wrap Up</h3>
<p>I hope you find this quick premier on JQuery effects useful. Please, add any corrections and suggestions to the comments. And, of course, <a href="http://www.twitter.com/simplrdesgn">follow me on Twitter</a> to get notified of the next JQuery installment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cherrysave.com/jquery/jquery-for-beginners-using-simple-jquery-effects-for-a-rockstar-user-interface/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Create a Hovering Scroll to Top Button With JQuery</title>
		<link>http://www.cherrysave.com/jquery/create-a-hovering-scroll-to-top-button-with-jquery/</link>
		<comments>http://www.cherrysave.com/jquery/create-a-hovering-scroll-to-top-button-with-jquery/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 04:39:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.cherrysave.com/?p=248</guid>
		<description><![CDATA[Looking for an easy way to help your readers power through long web pages? Sick of scrolling for minutes at a time to get to the top of the document? Here's a simple Scroll to Top button that hovers in the bottom right corner of your screen. Best of all, it's made entirely from JQuery, CSS, and HTML, so you can easily drop it into preexisting pages and customize it to your hearts content.]]></description>
			<content:encoded><![CDATA[<p>Looking for an easy way to help your readers power through long web pages? Sick of scrolling for minutes at a time to get to the top of the document? Here's a simple Scroll to Top button that hovers in the bottom right corner of your screen. Best of all, it's made entirely from JQuery, CSS, and HTML, so you can easily drop it into preexisting pages and customize it to your hearts content.</p><p><a href="http://api.tweetmeme.com/share?url=http://www.cherrysave.com/jquery/create-a-hovering-scroll-to-top-button-with-jquery/"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://www.cherrysave.com/jquery/create-a-hovering-scroll-to-top-button-with-jquery/" height="61" width="51" /></a></p><div id="attachment_249" class="wp-caption alignnone" style="width: 584px"><a id="single_image" href="http://cherrysave.com/wp-content/uploads/2009/11/scroll.jpg"><img class="size-full wp-image-249" title="JQuery Scroll to Top Button" src="http://cherrysave.com/wp-content/uploads/2009/11/scroll.jpg" alt="JQuery Hovering Scroll to Top Button" width="574" height="138" /></a><p class="wp-caption-text">JQuery Hovering Scroll to Top Button</p></div>
<p>Looking for an easy way to help your readers power through long web pages? Sick of scrolling for minutes at a time to get to the top of the document? Here&#8217;s a simple Scroll to Top button that hovers in the bottom right corner of your screen. Best of all, it&#8217;s made entirely from JQuery, CSS, and HTML, so you can easily drop it into preexisting pages and customize it to your hearts content.</p>
<p>The code is largely adapted from <a href="http://briancray.com/2009/10/06/scroll-to-top-link-jquery-css/">Brian Cray</a> and <a href="http://davidwalsh.name/jquery-top-link">David Walsh</a>, but it&#8217;s a combination of the two ideas with the addition of a fade effect on the button and smooth scrolling action. Also, I moved the button to the bottom right corner of the page because I thought it was a little less intrusive. The browser will nicely and smoothly scroll up to the anchor when users click the link, and this is thanks to the super helpful <a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html">ScrollTo plugin</a> for JQuery, built by Ariel Flesler.</p>
<p>What&#8217;s that? You want to see it in action? Okay, you should check out the <strong><a href="http://cherrysave.com/wp-content/uploads/2009/11/untitled.html">demo</a></strong>!</p>
<p>And without further ado, here&#8217;s the code. First, add the button and the anchor to your web page or template. The button should go at the bottom of your page, right above the <code>&lt;/body&gt; </code>tag. And, the anchor should go at the top of your page.</p>
<pre>
&lt;div id=&quot;top&quot;&gt;&lt;/div&gt; &lt;!--this goes at the top--&gt;
&lt;div id=&quot;message&quot;&gt;&lt;a href=&quot;#top&quot; id=&quot;top-link&quot;&gt;Scroll to Top&lt;/a&gt;&lt;/div&gt; &lt;!--this goes at the bottom--&gt;
</pre>
<p>Now, you&#8217;ll need some CSS to format the look and feel of the button. As you probably noticed, I left a gap at the bottom of the page so you can read the last few lines of text without being obstructed by the button. Here&#8217;s the stylesheet:</p>
<pre>
.container {padding: 0 0 70px 0;} /* the gap for the bottom */

#message
{
/* display: block before hiding */
display: block;
display: none;

/* link is above all other elements */
z-index: 999;

/* link doesn't hide text behind it */
opacity: .8;

/* link stays at same place on page */
position: fixed;

/* link goes at the bottom of the page */
top: 100%;
margin-top: -80px; /* = height + preferred bottom margin */

/* link is centered */
left: 80%;
margin-left: -80px;

/* round the corners (to your preference) */
-moz-border-radius: 24px;
-webkit-border-radius: 24px;

/* make it big and easy to see (size, style to preferences) */
width: 300px;
line-height: 48px;
height: 48px;
padding: 10px;
background-color: #000;
font-size: 24px;
text-align: center;
}

#message a { color: #fff; }
</pre>
<p>And, of course, the JQuery. Make sure you have JQuery and the ScrollTo plugin included in the source:</p>
<pre>
$(function () { // run this code on page load (AKA DOM load)

/* set variables locally for increased performance */
var scroll_timer;
var displayed = false;
var $message = $('#message');
var $window = $(window);
var top = $(document.body).children(0).position().top;

/* react to scroll event on window */
$window.scroll(function () {
window.clearTimeout(scroll_timer);
scroll_timer = window.setTimeout(function () { // use a timer for performance
if($window.scrollTop() &lt;= top) // hide if at the top of the page
{
displayed = false;
$message.fadeOut(500);
}
else if(displayed == false) // show if scrolling down
{
displayed = true;
$message.stop(true, true).fadeIn(500).click(function () { $message.fadeOut(500); });
}
}, 100);
});
$('#top-link').click(function(e) {
e.preventDefault();
$.scrollTo(0,300);
});
});
</pre>
<p>&#8230; and there you have it! Let me know how it works for you in the comments, and feel free to share the code snippet with friends. Include your suggestions as well: I&#8217;m interested in good ways to expand the functionality.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cherrysave.com/jquery/create-a-hovering-scroll-to-top-button-with-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
