<?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>Free Web Resources - Web Resources Depot &#187; Tutorials</title>
	<atom:link href="http://www.webresourcesdepot.com/category/extras/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webresourcesdepot.com</link>
	<description>Free Web Resources</description>
	<lastBuildDate>Sat, 21 Nov 2009 10:00:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ajaxed Sliding Shopping Cart With jQuery</title>
		<link>http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 08:53:24 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1084</guid>
		<description><![CDATA[With this 5th &#38; last post of the &#34;WRD E-Commerce Week&#34; we will be modifying &#34;our Ajaxed shopping cart&#34; to create a one which is very ideal for designs with limited spaces.
The shopping cart will:

be hidden at the top of the page that can be displayed with a show/hide link
open when an item is added [...]]]></description>
			<content:encoded><![CDATA[<p>With this 5th &amp; last post of the &quot;<a href="http://www.webresourcesdepot.com/e-commerce-week-at-webresourcesdepot-want-to-sponsor/">WRD E-Commerce Week</a>&quot; we will be modifying &quot;<a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">our Ajaxed shopping cart</a>&quot; to create a one which is very <strong>ideal for designs with limited spaces</strong>.</p>
<h3>The shopping cart will:</h3>
<ul>
<li>be hidden at the top of the page that can be displayed with a show/hide link</li>
<li>open when an item is added to the basket &amp; auto-close</li>
<li>require a manual &quot;hide&quot; click if opened manually</li>
<li>enable us to delete products</li>
</ul>
<p><img height="176" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/ajax-sliding-cart.gif" alt="Ajaxed Sliding Shopping Cart" /></p>
<p><a target="_blank" href="http://webresourcesdepot.com/wp-content/uploads/file/jbasket/sliding-basket/"><img height="48" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" alt="Ajaxed Sliding Shopping Cart With jQuery Demo" style="border: 0px none ;" /></a><a target="_blank" href="http://feeds2.feedburner.com/webresourcesdepot"><img src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-button.gif" alt="Ajaxed Sliding Shopping Cart With jQuery Download" style="border: 0px none ;" /></a></p>
<p><span id="more-1084"></span></p>
<div class="featured">
<h3>Sponsors Of E-Commerce Week:</h3>
<p><script type="text/javascript">
Vertical1240387 = false;
ShowAdHereBanner1240387 = false;
RepeatAll1240387 = false;
NoFollowAll1240387 = false;
BannerStyles1240387 = new Array(
    "a{display:block;font-size:11px;color:#888;font-family:verdana,sans-serif;margin:0 4px 10px 0;text-align:center;text-decoration:none;overflow:hidden;}",
    "img{border:0;clear:right;}",
    "a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}",
    "a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}"
);
document.write(unescape("%3Cscript src='"+document.location.protocol+"//s3.buysellads.com/1240387/1240387.js?v="+Date.parse(new Date())+"' type='text/javascript'%3E%3C/script%3E"));
</script> <a target="_blank" href="http://www.sslmatic.com/"><img height="60" width="468" style="border: 0px none ; padding: 0px;" alt="SSLmatic - Cheap SSL Certificates" src="http://www.webresourcesdepot.com/wp-content/uploads/image/sslmatic-468x60.jpg" /></a></p>
<p><a target="_blank" href="http://buysellads.com/buy/detail/325">Want To Sponsor?</a></p>
</div>
<h3>The HTML</h3>
<p><strong>For The Sliding Basket:</strong></p>
<pre class="brush: php">
&lt;div id=&quot;slidingTopWrap&quot;&gt;
	&lt;div id=&quot;slidingTopContent&quot;&gt;
		&lt;div id=&quot;basketWrap&quot;&gt;
			&lt;div id=&quot;basketTitleWrap&quot;&gt;
				Your Basket &lt;span id=&quot;notificationsLoader&quot;&gt;&lt;/span&gt;
			&lt;/div&gt;
			&lt;div id=&quot;basketItemsWrap&quot;&gt;
				&lt;ul&gt;
				&lt;li&gt;&lt;/li&gt;
				&lt;?php getBasket(); ?&gt;
				&lt;/ul&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div id=&quot;slidingTopFooter&quot;&gt;
		&lt;div id=&quot;slidingTopFooterLeft&quot;&gt;
			&lt;img src=&quot;images/arrow-down.png&quot; alt=&quot;Show Basket&quot; /&gt; &lt;a href=&quot;no-js.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Show Basket&lt;/a&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The Highlights</p>
<ul>
<li>the div <code>slidingTopWrap</code> is positioned absolutely with top: 0 CSS value to stick to the top of the page</li>
<li>the div <code>slidingTopContent</code> is hided via JavaScript when the page loads &amp; it is actually the part which slides</li>
<li>the div <code>basketWrap</code>, nothing unusual, wraps the contents of the basket</li>
</ul>
<h3>The JavaScript (jQuery)</h3>
<p><strong>Manual Show/Hide Part</strong></p>
<pre class="brush: javascript">
$(&quot;#slidingTopContent&quot;).hide();

$(&quot;#slidingTopTrigger&quot;).live(&quot;click&quot;, function(event) {
	$(&quot;#slidingTopContent&quot;).slideToggle(&quot;slow&quot;, function(){
		if ($(&quot;#slidingTopContent&quot;).is(&quot;:visible&quot;)) {
			$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-up.png&quot; alt=&quot;Hide Basket&quot; /&gt; &lt;a href=&quot;no-js.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Hide Basket&lt;/a&gt;&#039;);
		} else {
			$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-down.png&quot; alt=&quot;Show Basket&quot; /&gt; &lt;a href=&quot;no-js.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Show Basket&lt;/a&gt;&#039;);
		}
	});
}); 
</pre>
<p>The Highlights:</p>
<ul>
<li>we have <code>$(&quot;#slidingTopContent&quot;).hide();</code> in the beginning to hide the div in the initial load</li>
<li>when the #slidingTopTrigger is clicked, we use the <code>slideToggle</code> function to show/hide the #slidingTopContent. To understand whether it is open or not, we have an if then else clause as <code>if ($(&quot;#slidingTopContent&quot;).is(&quot;:visible&quot;)) {</code>
<ul>
<li>if the #slidingTopContent is visible, we insert the &quot;hide HTML&quot;</li>
<li>if the #slidingTopContent is <strong>not</strong> visible, we insert the &quot;show HTML&quot;</li>
</ul>
</li>
<li>you&#8217;ll see that we used the <code>$(&quot;#slidingTopTrigger&quot;).live(&quot;click&quot;, function(event) {</code> rather than a standard click function. The reason is adding the new created HTMLs to the DOM</li>
</ul>
<p><strong>Adding Products</strong></p>
<pre class="brush: javascript">
$(&quot;.productPriceWrapRight a img&quot;).click(function() {
	var productIDValSplitter 	= (this.id).split(&quot;_&quot;);
	var productIDVal 			= productIDValSplitter[1];

	if ($(&quot;#slidingTopContent&quot;).is(&quot;:visible&quot;)) {

		$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

		$.ajax({
		type: &quot;POST&quot;,
		url: &quot;inc/functions.php&quot;,
		data: { productID: productIDVal, action: &quot;addToBasket&quot;},
		success: function(theResponse) {

		if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
			$(&quot;#notificationsLoader&quot;).empty();

		} else {
			$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
			$(&quot;#basketItemsWrap li:first&quot;).hide();
			$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
			$(&quot;#notificationsLoader&quot;).empty();
		}

		}
		}); 

	} else {

		$(&quot;#slidingTopContent&quot;).slideToggle(&quot;slow&quot;, function(){		

			$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-up.png&quot; alt=&quot;Hide Basket&quot; /&gt; &lt;a href=&quot;aaa.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Hide Basket&lt;/a&gt;&#039;);
			$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

			$.ajax({
			type: &quot;POST&quot;,
			url: &quot;inc/functions.php&quot;,
			data: { productID: productIDVal, action: &quot;addToBasket&quot;},
			success: function(theResponse) {

			if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
				$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
				$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
				$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
				$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
				$(&quot;#notificationsLoader&quot;).empty();

			} else {
				$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
				$(&quot;#basketItemsWrap li:first&quot;).hide();
				$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
				$(&quot;#notificationsLoader&quot;).empty();
			}

			}
			}); 

			$(&quot;#slidingTopTrigger&quot;).fadeTo(4000, 1, function(){
				$(&quot;#slidingTopContent&quot;).slideToggle(&quot;slow&quot;, function(){
					$(&quot;#slidingTopFooterLeft&quot;).html(&#039;&lt;img src=&quot;images/arrow-down.png&quot; alt=&quot;Show Basket&quot; /&gt; &lt;a href=&quot;aaa.htm&quot; onclick=&quot;return false;&quot; id=&quot;slidingTopTrigger&quot;&gt;Show Basket&lt;/a&gt;&#039;);
				});

			});

		});
	}

});
</pre>
<p>The Highlights:</p>
<p>As &quot;how-to&quot; on sending the Ajax query &amp; fading animations are described in the <a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">previous post</a>, we won&#8217;t repeating the same info here &amp; focus on the effects.</p>
<ul>
<li>we again run the same if-then-else clause
<ul>
<li>if the #slidingTopContent is open send an Ajax query to functions.php and add-the-products to basket</li>
<li>if the #slidingTopContent is closed:
<ul>
<li>slideToggle the div</li>
<li>insert the &quot;hide HTML&quot; to #slidingTopFooterLeft&quot;</li>
<li>send an Ajax query to functions.php and add-the-products to basket</li>
<li>wait for x seconds:&nbsp;<code>$(&quot;#slidingTopTrigger&quot;).fadeTo(4000, 1, function(){</code></li>
<li>slideToggle the div</li>
<li>insert the &quot;show HTML&quot; to #slidingTopFooterLeft&quot;</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>P.S.</strong> To make the example work on your side, you should be creating a new database with the jBasket.sql file inside the download package &amp; configure the database connection information inside &ldquo;inc/db.php&rdquo; file.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a><br />
<a href="http://twitter.com/umutm" target="_blank">Follow WebResourcesDepot At Twitter And Get More Resources!</a></p>

	Tags: <a href="http://www.webresourcesdepot.com/tag/javascript/" title="Javascript" rel="tag">Javascript</a>, <a href="http://www.webresourcesdepot.com/tag/php/" title="Php" rel="tag">Php</a><br />

	<h4>Related posts</h4>
	<ul class='st-related-posts'>
	<li><a href="http://www.webresourcesdepot.com/use-php-functions-in-javascript-phpjs/" title="Use PHP Functions In JavaScript: PHP.JS (May 28, 2009)">Use PHP Functions In JavaScript: PHP.JS</a></li>
	<li><a href="http://www.webresourcesdepot.com/use-any-font-in-your-websites-with-flir/" title="Use Any Font In Your Websites With FLIR (August 5, 2008)">Use Any Font In Your Websites With FLIR</a></li>
	<li><a href="http://www.webresourcesdepot.com/track-mouse-activities-with-js-and-php-smt/" title="Track Mouse Activities With JS And PHP: (smt) (June 29, 2009)">Track Mouse Activities With JS And PHP: (smt)</a></li>
	<li><a href="http://www.webresourcesdepot.com/tiny-content-management-system-onefilecms/" title="Tiny Content Management System: OneFileCMS (September 30, 2009)">Tiny Content Management System: OneFileCMS</a></li>
	<li><a href="http://www.webresourcesdepot.com/testswarm-continious-distributed-js-testing/" title="TestSwarm: Continious &#038; Distributed JS Testing (August 27, 2009)">TestSwarm: Continious &#038; Distributed JS Testing</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Fly-To-Basket Effect With jQuery</title>
		<link>http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 07:52:37 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1080</guid>
		<description><![CDATA[In this 3rd day of the &#34;WRD E-Commerce Week&#34;, we will be adding a chic fly-to-basket effect to our previously created Ajaxed shopping cart using jQuery.
Rather than the complete HTML structure &#38; PHP code that adds/removes the products, we&#8217;ll be focusing on the details related with&#160; the effect.

To findout the details of the complete HTML [...]]]></description>
			<content:encoded><![CDATA[<p>In this 3rd day of the &quot;<a href="http://www.webresourcesdepot.com/e-commerce-week-at-webresourcesdepot-want-to-sponsor/">WRD E-Commerce Week</a>&quot;, we will be adding a chic <strong>fly-to-basket effect</strong> to our <a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">previously created Ajaxed shopping cart</a> using <strong>jQuery</strong>.</p>
<p>Rather than the complete HTML structure &amp; PHP code that adds/removes the products, <strong>we&#8217;ll be focusing on the details related with&nbsp; the effect</strong>.</p>
<p><img height="156" width="480" alt="Fly To Basket With jQuery" src="http://www.webresourcesdepot.com/wp-content/uploads/image/fly-to-basket-jquery.jpg" /></p>
<p>To findout the details of the complete HTML structure &amp; PHP code, please check our post: <a href="http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/">Creating A Slick Ajaxed Add-To-Basket With jQuery And PHP</a>. And, a full working example can be found in the download package.</p>
<p><a href="http://webresourcesdepot.com/wp-content/uploads/file/jbasket/fly-to-basket/" target="_blank"><img height="48" width="480" style="border: 0px none ;" alt="Fly-To-Basket Effect With jQuery Demo" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" /></a><a href="http://feeds2.feedburner.com/webresourcesdepot" target="_blank"><img style="border: 0px none ;" alt="Fly-To-Basket Effect With jQuery Download" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-button.gif" /></a></p>
<p><span id="more-1080"></span></p>
<div class="featured">
<h3>Sponsors Of E-Commerce Week:</h3>
<p><script type="text/javascript">
Vertical1240387 = false;
ShowAdHereBanner1240387 = false;
RepeatAll1240387 = false;
NoFollowAll1240387 = false;
BannerStyles1240387 = new Array(
    "a{display:block;font-size:11px;color:#888;font-family:verdana,sans-serif;margin:0 4px 10px 0;text-align:center;text-decoration:none;overflow:hidden;}",
    "img{border:0;clear:right;}",
    "a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}",
    "a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}"
);
document.write(unescape("%3Cscript src='"+document.location.protocol+"//s3.buysellads.com/1240387/1240387.js?v="+Date.parse(new Date())+"' type='text/javascript'%3E%3C/script%3E"));
</script> <a href="http://www.sslmatic.com/" target="_blank"><img width="468" height="60" src="http://www.webresourcesdepot.com/wp-content/uploads/image/sslmatic-468x60.jpg" alt="SSLmatic - Cheap SSL Certificates" style="border: 0px none ; padding: 0px;" /></a></p>
<p><a href="http://buysellads.com/buy/detail/325" target="_blank">Want To Sponsor?</a></p>
</div>
<h3>The HTML</h3>
<p><strong>HTML For The Product&#8217;s Wrapper:</strong></p>
<pre class="brush: php">
&lt;div class=&quot;productWrap&quot;&gt;
	&lt;div class=&quot;productImageWrap&quot;&gt;
		&lt;img src=&quot;images/product1.jpg&quot; alt=&quot;Product1&quot; /&gt;
	&lt;/div&gt;
	&lt;div class=&quot;productNameWrap&quot;&gt;
		Krups Coffee Maker
	&lt;/div&gt;
	&lt;div class=&quot;productPriceWrap&quot;&gt;
		&lt;div class=&quot;productPriceWrapLeft&quot;&gt;
			$95
		&lt;/div&gt;
		&lt;div class=&quot;productPriceWrapRight&quot;&gt;
			&lt;a href=&quot;inc/functions.php?action=addToBasket&amp;productID=1&quot; onClick=&quot;return false;&quot;&gt;
				&lt;img src=&quot;images/add-to-basket.gif&quot; alt=&quot;Add To Basket&quot; width=&quot;111&quot; height=&quot;32&quot; id=&quot;featuredProduct_1&quot; /&gt;
			&lt;/a&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The part we&#8217;ll focus is the contents inside <code>&lt;div class=&quot;productPriceWrapRight&quot;&gt;</code> which wraps the &quot;add-to-basket&quot; button.</p>
<p>The Highlights:</p>
<ul>
<li>a link with <code>onClick=&quot;return false;</code> value which means it won&#8217;t be active if JavaScript is active (to make the script unobtrusive)</li>
<li>add-to-basket image has an unique ID: <code>id=&quot;featuredProduct_1&quot;</code> which we&#8217;ll use to understand the button of which product is clicked</li>
</ul>
<p><strong>HTML For The Basket:</strong></p>
<pre class="brush: php">
&lt;div id=&quot;basketWrap&quot;&gt;
	&lt;div id=&quot;basketTitleWrap&quot;&gt;
		Your Basket &lt;span id=&quot;notificationsLoader&quot;&gt;&lt;/span&gt;
	&lt;/div&gt;
	&lt;div id=&quot;basketItemsWrap&quot;&gt;
		&lt;ul&gt;
		&lt;li&gt;&lt;/li&gt;
		&lt;?php getBasket(); ?&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The Highlights:</p>
<ul>
<li>we have an empty <code>&lt;span&gt;</code> with <code>id=&quot;notificationsLoader&quot;</code> to show a loading image</li>
<li>we keep an empty div to be able to insert any data before/after them</li>
<li>we call a PHP function: <code>&lt;?php getBasket(); ?&gt;</code> to get the basket data when the page is first loaded.</li>
</ul>
<h3>The JavaScript (jQuery)</h3>
<pre class="brush: javascript">
$(&quot;#basketItemsWrap li:first&quot;).hide();

$(&quot;.productPriceWrapRight a img&quot;).click(function() {
	var productIDValSplitter 	= (this.id).split(&quot;_&quot;);
	var productIDVal 			= productIDValSplitter[1];

	var productX 		= $(&quot;#productImageWrapID_&quot; + productIDVal).offset().left;
	var productY 		= $(&quot;#productImageWrapID_&quot; + productIDVal).offset().top;

	if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
		var basketX 		= $(&quot;#productID_&quot; + productIDVal).offset().left;
		var basketY 		= $(&quot;#productID_&quot; + productIDVal).offset().top;
	} else {
		var basketX 		= $(&quot;#basketTitleWrap&quot;).offset().left;
		var basketY 		= $(&quot;#basketTitleWrap&quot;).offset().top;
	}

	var gotoX 			= basketX - productX;
	var gotoY 			= basketY - productY;

	var newImageWidth 	= $(&quot;#productImageWrapID_&quot; + productIDVal).width() / 3;
	var newImageHeight	= $(&quot;#productImageWrapID_&quot; + productIDVal).height() / 3;

	$(&quot;#productImageWrapID_&quot; + productIDVal + &quot; img&quot;)
	.clone()
	.prependTo(&quot;#productImageWrapID_&quot; + productIDVal)
	.css({&#039;position&#039; : &#039;absolute&#039;})
	.animate({opacity: 0.4}, 100 )
	.animate({opacity: 0.1, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200, function() {
																																																																												$(this).remove();

		$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

		$.ajax({
		type: &quot;POST&quot;,
		url: &quot;inc/functions.php&quot;,
		data: { productID: productIDVal, action: &quot;addToBasket&quot;},
		success: function(theResponse) {

		if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
			$(&quot;#notificationsLoader&quot;).empty();

		} else {
			$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
			$(&quot;#basketItemsWrap li:first&quot;).hide();
			$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
			$(&quot;#notificationsLoader&quot;).empty();
		}

		}
		});  

	});

});
</pre>
<p>Highlights:</p>
<ul>
<li><strong>splitting the ID&nbsp;of the clicked &quot;add-to-basket&quot; image</strong> which is &quot;featuredProduct_1&quot; from the &quot;_&quot; character &amp; get the databaseID of the product</li>
<li>using <a target="_blank" href="http://docs.jquery.com/CSS/offset">jQuery&#8217;s offset</a>, we get the current x-y position of the product</li>
<li>run a &quot;if-then-else&quot; clause which:
<ul>
<li><strong>if that product is already in the basket:</strong> <code>if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){</code> (if an element with that ID exists in the basket), if exists, then we get the x-y positions of that element using &quot;offset&quot; again, so we can target that element while flying our product</li>
<li><strong>if that product isn&#8217;t in the basket:</strong> then we get the x-y positions of a static element in the basket HTMl area (#basketTitleWrap in our case)</li>
</ul>
</li>
<li><strong>very important</strong>:&nbsp;we create 2 variables; gotoX &amp; gotoY by subtracting the element in the basket&#8217;s position from the product&#8217;s position. And we get the distance product needs to animate (fly) in x&#8217;s &amp; y&#8217;s</li>
<li>again create 2 variables named newImageWidth &amp; newImageHeight which are x times (3 in our case) smaller the size of our product&#8217;s image. This is used to create a resizing effect while flying the product to the basket</li>
<li><strong>and, let&#8217;s fly the product</strong>: targeting the product image to be flied;&nbsp;<code>$(&quot;#productImageWrapID_&quot; + productIDVal + &quot; img&quot;)</code>. We clone it with <a target="_blank" href="http://docs.jquery.com/Manipulation/clone">jQuery&#8217;s clone,</a> place inside the same element where the original image exists with <a target="_blank" href="http://docs.jquery.com/Manipulation/prependTo">prependTo</a> &amp; set it&#8217;s position to <code>absolute</code>. The next thing, we decrease its opacity so it starts in a little transparent look before the animation. And, we fly it by mentioning the <code>marginLeft</code> &amp; <code>marginTop</code> values we calculated. At the same time, we make it more transparent &amp; resize it. Also, we set the duration of the animation (1200 in our case).</li>
<li>As a callback function (after the animation ends), we remove the cloned image from the DOM, show the Ajax loader &amp; post a query to our PHP page. That&#8217;s all.</li>
</ul>
<p><strong>P.S.</strong> To make the example work on your side, you should be creating a new database with the jBasket.sql file inside the download package &amp; configure the database connection information inside “inc/db.php” file.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a><br />
<a href="http://twitter.com/umutm" target="_blank">Follow WebResourcesDepot At Twitter And Get More Resources!</a></p>

	Tags: <a href="http://www.webresourcesdepot.com/tag/javascript/" title="Javascript" rel="tag">Javascript</a>, <a href="http://www.webresourcesdepot.com/tag/php/" title="Php" rel="tag">Php</a><br />

	<h4>Related posts</h4>
	<ul class='st-related-posts'>
	<li><a href="http://www.webresourcesdepot.com/use-php-functions-in-javascript-phpjs/" title="Use PHP Functions In JavaScript: PHP.JS (May 28, 2009)">Use PHP Functions In JavaScript: PHP.JS</a></li>
	<li><a href="http://www.webresourcesdepot.com/use-any-font-in-your-websites-with-flir/" title="Use Any Font In Your Websites With FLIR (August 5, 2008)">Use Any Font In Your Websites With FLIR</a></li>
	<li><a href="http://www.webresourcesdepot.com/track-mouse-activities-with-js-and-php-smt/" title="Track Mouse Activities With JS And PHP: (smt) (June 29, 2009)">Track Mouse Activities With JS And PHP: (smt)</a></li>
	<li><a href="http://www.webresourcesdepot.com/tiny-content-management-system-onefilecms/" title="Tiny Content Management System: OneFileCMS (September 30, 2009)">Tiny Content Management System: OneFileCMS</a></li>
	<li><a href="http://www.webresourcesdepot.com/testswarm-continious-distributed-js-testing/" title="TestSwarm: Continious &#038; Distributed JS Testing (August 27, 2009)">TestSwarm: Continious &#038; Distributed JS Testing</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Creating A Slick Ajaxed Add-To-Basket With jQuery And PHP</title>
		<link>http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/</link>
		<comments>http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 07:05:40 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[E-Commerce]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[No License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=1071</guid>
		<description><![CDATA[It is a clear fact that Ajaxed interfaces, if not overused, eases using websites so much.
For an e-commerce website, this can mean a better shopping experience for customers where they can concentrate more on the products which may result in better sales.

This is a detailed tutorial which shows creating an unobtrusive Ajaxed shopping cart using [...]]]></description>
			<content:encoded><![CDATA[<p>It is a clear fact that Ajaxed interfaces, if not overused, eases using websites so much.</p>
<p>For an e-commerce website, this can mean <strong>a better shopping experience for customers</strong> where they can concentrate more on the products which may result in better sales.</p>
<p><img width="480" height="160" alt="jQuery Ajax Shopping Cart" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-ajax-shopping-cart.jpg" /></p>
<p>This is a detailed tutorial which shows creating an <strong>unobtrusive Ajaxed shopping cart using <strong>jQuery</strong> &amp; <strong>PHP</strong> </strong>and can guide you to Ajaxify any e-commerce software you may already be using or coding.</p>
<p>The main functions of the cart will be adding/removing items to the basket without the need of refreshing the page &amp; displaying the actions with effects.</p>
<h3>Other Add-To-Basket Tutorials Built on This Example:</h3>
<ul>
<li><a href="http://www.webresourcesdepot.com/fly-to-basket-effect-with-jquery/">Fly-To-Basket Effect With jQuery</a></li>
<li><a href="http://www.webresourcesdepot.com/ajaxed-sliding-shopping-cart-with-jquery/">Ajaxed Sliding Shopping Cart With jQuery</a></li>
</ul>
<p><span id="more-1071"></span></p>
<p>To try the demo or download the script:</p>
<p><a target="_blank" href="http://webresourcesdepot.com/wp-content/uploads/file/jbasket/standard/"><img width="480" height="48" src="http://www.webresourcesdepot.com/wp-content/uploads/image/demo-button.gif" alt="Slick Add-To-Basket With jQuery And PHP Demo" style="border: 0px none ;" /></a><a target="_blank" href="http://feeds2.feedburner.com/webresourcesdepot"><img src="http://www.webresourcesdepot.com/wp-content/uploads/image/download-button.gif" alt="Slick Add-To-Basket With jQuery And PHP Download" style="border: 0px none ;" /></a></p>
<div class="featured">
<h3>Sponsors Of E-Commerce Week:</h3>
<p><script type="text/javascript">
Vertical1240387 = false;
ShowAdHereBanner1240387 = false;
RepeatAll1240387 = false;
NoFollowAll1240387 = false;
BannerStyles1240387 = new Array(
    "a{display:block;font-size:11px;color:#888;font-family:verdana,sans-serif;margin:0 4px 10px 0;text-align:center;text-decoration:none;overflow:hidden;}",
    "img{border:0;clear:right;}",
    "a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}",
    "a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}"
);
document.write(unescape("%3Cscript src='"+document.location.protocol+"//s3.buysellads.com/1240387/1240387.js?v="+Date.parse(new Date())+"' type='text/javascript'%3E%3C/script%3E"));
</script> <a href="http://www.sslmatic.com/" target="_blank"><img width="468" height="60" src="http://www.webresourcesdepot.com/wp-content/uploads/image/sslmatic-468x60.jpg" alt="SSLmatic - Cheap SSL Certificates" style="border: 0px none ; padding: 0px;" /></a></p>
<p><a href="http://buysellads.com/buy/detail/325" target="_blank">Want To Sponsor?</a></p>
</div>
<h3>The HTML</h3>
<p>Rather than the formatting of the page, as you can design it however you prefer, we&#8217;ll be focusing on the vital parts which does all the tricks.</p>
<p><strong>HTML For The Product&#8217;s Wrapper:</strong></p>
<pre class="brush: php">
&lt;div class=&quot;productWrap&quot;&gt;
	&lt;div class=&quot;productImageWrap&quot;&gt;
		&lt;img src=&quot;images/product1.jpg&quot; alt=&quot;Product1&quot; /&gt;
	&lt;/div&gt;
	&lt;div class=&quot;productNameWrap&quot;&gt;
		Krups Coffee Maker
	&lt;/div&gt;
	&lt;div class=&quot;productPriceWrap&quot;&gt;
		&lt;div class=&quot;productPriceWrapLeft&quot;&gt;
			$95
		&lt;/div&gt;
		&lt;div class=&quot;productPriceWrapRight&quot;&gt;
			&lt;a href=&quot;inc/functions.php?action=addToBasket&amp;productID=1&quot; onClick=&quot;return false;&quot;&gt;
				&lt;img src=&quot;images/add-to-basket.gif&quot; alt=&quot;Add To Basket&quot; width=&quot;111&quot; height=&quot;32&quot; id=&quot;featuredProduct_1&quot; /&gt;
			&lt;/a&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The part we&#8217;ll focus is the contents inside <code>&lt;div class=&quot;productPriceWrapRight&quot;&gt;</code> which wraps the &quot;add-to-basket&quot; button.</p>
<p>The Highlights:</p>
<ul>
<li>a link with <code>onClick=&quot;return false;</code> value which means it won&#8217;t be active if JavaScript is active (to make the script unobtrusive)</li>
<li>add-to-basket image has an unique ID: <code>id=&quot;featuredProduct_1&quot;</code> which we&#8217;ll use to understand the button of which product is clicked</li>
</ul>
<p><strong>HTML For The Basket:</strong></p>
<pre class="brush: php">
&lt;div id=&quot;basketWrap&quot;&gt;
	&lt;div id=&quot;basketTitleWrap&quot;&gt;
		Your Basket &lt;span id=&quot;notificationsLoader&quot;&gt;&lt;/span&gt;
	&lt;/div&gt;
	&lt;div id=&quot;basketItemsWrap&quot;&gt;
		&lt;ul&gt;
		&lt;li&gt;&lt;/li&gt;
		&lt;?php getBasket(); ?&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>The Highlights:</p>
<ul>
<li>we have an empty <code>&lt;span&gt;</code> with <code>id=&quot;notificationsLoader&quot;</code> to show a loading image</li>
<li>we keep an empty div to be able to insert any data before/after them</li>
<li>we call a PHP function: <code>&lt;?php getBasket(); ?&gt;</code> to get the basket data when the page is first loaded.</li>
</ul>
<h3>The JavaScript (jQuery)</h3>
<p>We have 2 main jQuery functions:</p>
<p><strong>Function For Adding To Basket:</strong></p>
<pre class="brush: javascript">
$(&quot;.productPriceWrapRight a img&quot;).click(function() {
	var productIDValSplitter 	= (this.id).split(&quot;_&quot;);
	var productIDVal 			= productIDValSplitter[1];

	$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

	$.ajax({
	type: &quot;POST&quot;,
	url: &quot;inc/functions.php&quot;,
	data: { productID: productIDVal, action: &quot;addToBasket&quot;},
	success: function(theResponse) {

		if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500, function() {
				$(&quot;#productID_&quot; + productIDVal).before(theResponse).remove();
			});
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 0 }, 500);
			$(&quot;#productID_&quot; + productIDVal).animate({ opacity: 1 }, 500);
			$(&quot;#notificationsLoader&quot;).empty();
		} else {
			$(&quot;#basketItemsWrap li:first&quot;).before(theResponse);
			$(&quot;#basketItemsWrap li:first&quot;).hide();
			$(&quot;#basketItemsWrap li:first&quot;).show(&quot;slow&quot;);
			$(&quot;#notificationsLoader&quot;).empty();
		}

	}
	});  

});
</pre>
<p>The Highlights:</p>
<ul>
<li><strong>splitting the ID&nbsp;of the clicked &quot;add-to-basket&quot; image</strong> which is &quot;featuredProduct_1&quot; from the &quot;_&quot; character &amp; get the databaseID of the product (1)</li>
<li>inserting the <code>loader.gif</code>image inside the element with <code>id=&quot;notificationsLoader&quot;</code></li>
<li>posting a data with Ajax to our functions.php fil which handles all the server-side jobs. 2 data are posted: <code>productID</code> and the action to be done which is <code>addToBasket</code></li>
<li>There are 2 possibilities when the data is posted, the items may already be inside the basket or it may be a new item. So, we have an if clause: <code>if( $(&quot;#productID_&quot; + productIDVal).length &gt; 0){</code> which checks if an element with ID: productID<strong>1</strong> (1 is a variable) exists in the page
<ul>
<li>&nbsp;if it exist:
<ul>
<li>we change the opacity of that object to 0 (make it invisible)</li>
<li>load the new <code>&lt;li&gt;product info&lt;/li&gt;</code> response that comes from the functions.php</li>
<li>remove the original <code>&lt;li&gt;product info&lt;/li&gt;</code> object whose opacity was 0</li>
<li>and play with the new <code>&lt;li&gt;product info&lt;/li&gt;</code> object&#8217;s opacity to create a blinking effect</li>
<li>empty the contents inside<code> id=&quot;notificationsLoader&quot;</code> to stop the loading animation</li>
</ul>
</li>
<li>if it does not exist:
<ul>
<li>we insert the response from the functions.php before the first hidden &lt;li&gt; and hide it</li>
<li>then use <strong>jQuery&#8217;s show function</strong> to display it with an effect</li>
<li>empty the contents inside<code> id=&quot;notificationsLoader&quot;</code> to stop the loading animation</li>
</ul>
</li>
</ul>
</li>
</ul>
<p><strong>Function For Removing From Basket:</strong></p>
<pre class="brush: javascript">
$(&quot;#basketItemsWrap li img&quot;).live(&quot;click&quot;, function(event) { 

	var productIDValSplitter 	= (this.id).split(&quot;_&quot;);
	var productIDVal 			= productIDValSplitter[1];	

	$(&quot;#notificationsLoader&quot;).html(&#039;&lt;img src=&quot;images/loader.gif&quot;&gt;&#039;);

	$.ajax({
	type: &quot;POST&quot;,
	url: &quot;inc/functions.php&quot;,
	data: { productID: productIDVal, action: &quot;deleteFromBasket&quot;},
	success: function(theResponse) {

		$(&quot;#productID_&quot; + productIDVal).hide(&quot;slow&quot;,  function() {$(this).remove();});
		$(&quot;#notificationsLoader&quot;).empty();

	}
	});  

});
</pre>
<p>The Highlights:</p>
<ul>
<li>As the objects are inserted to basket via Ajax, the new HTML items inside the basket are normally not loaded to the DOM and we can&#8217;t reach them via JavaScript. <strong>jQuery offers an event named &quot;live&quot;</strong> (starting from jQuery 1.3) which loads the new created items to the DOM. So we used this event.</li>
<li>All other tasks are similar to adding an item, we splitted the HTML element from the &quot;_&quot; character and got the <code>productID</code> to be deleted and sent it to functions.php via Ajax.</li>
</ul>
<h3>The Database</h3>
<p>We have used a MySQL database in this example with 2 tables:</p>
<p><strong>Products</strong>:</p>
<p><img width="480" height="90" src="http://www.webresourcesdepot.com/wp-content/uploads/image/add-to-basket-db-table2.jpg" alt="Add To Basket Products Table" /></p>
<p><strong>Baskets</strong> (for keeping the shopping cart of every different session)</p>
<p><img width="480" height="90" src="http://www.webresourcesdepot.com/wp-content/uploads/image/add-to-basket-db-table1.jpg" alt="Add To Basket Sessions Table" /></p>
<h3>The PHP</h3>
<p>There is nothing complicated on the PHP part.</p>
<p><strong>Handle The Variables:</strong></p>
<pre class="brush: php">
session_start();
$sessionID = $_COOKIE[&#039;PHPSESSID&#039;];

if($_POST[&#039;action&#039;] != &#039;&#039; || $_GET[&#039;action&#039;] != &#039;&#039;) {
	if($_POST[&#039;action&#039;] == &#039;&#039;)
	{
		$action 	= $_GET[&#039;action&#039;];
		$productID	= $_GET[&#039;productID&#039;];
		$noJavaScript = 1;
	} else {
		$action 	= $_POST[&#039;action&#039;];
		$productID	= $_POST[&#039;productID&#039;];
		$noJavaScript = 0;
	}
}
</pre>
<p>The Highlights:</p>
<ul>
<li>we <strong>create a session variable</strong> so every different user will have their own baskets</li>
<li>understand if the request comes from a POST (Ajax) or GET (JS disabled) request and get the <code>action</code> &amp; <code>productID</code> variables</li>
<li>if it is a GET request we change the value of a variable named <code>$noJavaScript</code> to 1</li>
</ul>
<p><strong>PHP For Add To Basket:</strong></p>
<pre class="brush: php">
if ($action == &quot;addToBasket&quot;){

	$productInBasket 	= 0;
	$productTotalPrice	= 0;

	$query  = &quot;SELECT * FROM products WHERE productID = &quot; . $productID;
	$result = mysql_query($query);
	$row = mysql_fetch_array( $result );

	$productPrice 		= $row[&#039;productPrice&#039;];
	$productName		= $row[&#039;productName&#039;];	

	$query = &quot;INSERT INTO baskets (productID, productPrice, basketSession) VALUES (&#039;$productID&#039;, &#039;$productPrice&#039;, &#039;$sessionID&#039;)&quot;;
	mysql_query($query) or die(&#039;Error, insert query failed&#039;);	

	$query  = &quot;SELECT * FROM baskets WHERE productID = &quot; . $productID . &quot; AND basketSession = &#039;&quot; . $sessionID . &quot;&#039;&quot;;
	$result = mysql_query($query) or die(mysql_error());;

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$totalItems 	= $totalItems + 1;
		$productTotalPrice 	= $productTotalPrice + $row[&#039;productPrice&#039;];
	}

	if ($noJavaScript == 1) {
		header(&quot;Location: ../index.php&quot;);
	} else {
		echo (&#039;&lt;li id=&quot;productID_&#039; . $productID . &#039;&quot;&gt;&lt;a href=&quot;inc/functions.php?action=deleteFromBasket&amp;productID=&#039; . $productID . &#039;&quot; onClick=&quot;return false;&quot;&gt;&lt;img src=&quot;images/delete.png&quot; id=&quot;deleteProductID_&#039; . $productID . &#039;&quot;&gt;&lt;/a&gt; &#039; . $productName . &#039;(&#039; . $totalItems . &#039; items) - $&#039; . $productTotalPrice . &#039;&lt;/li&gt;&#039;);
	}

}
</pre>
<p>The Highlights:</p>
<ul>
<li>we insert the product to the database. If <code>$noJavaScript</code> to 1 we redirect to the index.php else <strong>we create a &lt;li&gt; element</strong> including the product&#8217;s details &amp; <strong><code>echo</code> it so we can insert it via jQuery</strong>.</li>
</ul>
<p><strong>PHP For Delete From Basket:</strong></p>
<pre class="brush: php">
if ($action == &quot;deleteFromBasket&quot;){

	$query = &quot;DELETE FROM baskets WHERE productID = &quot; . $productID . &quot; AND basketSession = &#039;&quot; . $sessionID . &quot;&#039;&quot;;
	mysql_query($query) or die(&#039;Error, delete query failed&#039;);

	if ($noJavaScript == 1) {
		header(&quot;Location: ../index.php&quot;);
	}
}
</pre>
<p>The Highlights:</p>
<ul>
<li>we delete the product to the database. If <code>$noJavaScript</code> to 1 we redirect to the index.php</li>
</ul>
<p><strong>PHP For Getting The Basket (For Initial Load)</strong></p>
<p>Like mentioned before, we create a function to get the basket&#8217;s current situation, so it can be loaded in the initial loading of the page.</p>
<pre class="brush: php">
function getBasket(){

	session_start();
	$sessionID = $_COOKIE[&#039;PHPSESSID&#039;];

	$query  = &quot;SELECT * FROM baskets WHERE basketSession = &#039;&quot; . $sessionID . &quot;&#039; GROUP BY productID ORDER By basketID DESC&quot;;
	$result = mysql_query($query);
	//echo $query;

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{

		$query2  = &quot;SELECT * FROM products WHERE productID = &quot; . $row[&#039;productID&#039;];
		$result2 = mysql_query($query2);
		$row2 = mysql_fetch_array( $result2 );

		$productID	 		= $row2[&#039;productID&#039;];
		$productPrice 		= $row2[&#039;productPrice&#039;];
		$productName		= $row2[&#039;productName&#039;];	

		$query2  = &quot;SELECT COUNT(*) AS totalItems FROM baskets WHERE basketSession = &#039;&quot; . $sessionID . &quot;&#039; AND productID = &quot; . $productID;
		$result2 = mysql_query($query2);
		$row2 = mysql_fetch_array( $result2 );
		$totalItems = $row2[&#039;totalItems&#039;];
		$basketText = $basketText . &#039;&lt;li id=&quot;productID_&#039; . $productID . &#039;&quot;&gt;&lt;a href=inc/functions.php?action=deleteFromBasket&amp;productID=&#039; . $productID . &#039; onClick=&quot;return false;&quot;&gt;&lt;img src=&quot;images/delete.png&quot; id=&quot;deleteProductID_&#039; . $productID . &#039;&quot;&gt;&lt;/a&gt; &#039; . $productName . &#039;(&#039; . $totalItems . &#039; items) - $&#039; . ($totalItems * $productPrice) . &#039;&lt;/li&gt;&#039;;

	}
	echo $basketText;
}
</pre>
<p>The Highlights:</p>
<ul>
<li>This is a standard PHP function which creates the HTML for the items in the basket with a loop</li>
</ul>
<p>And, the <strong>Ajaxed basket built with jQuery &amp; PHP</strong> is ready-to-use.</p>
<p><strong>P.S.</strong> To make the example work on your side, you should be creating a new database with the jBasket.sql file inside the download package &#038; configure the database connection information inside &#8220;inc/db.php&#8221; file.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a><br />
<a href="http://twitter.com/umutm" target="_blank">Follow WebResourcesDepot At Twitter And Get More Resources!</a></p>

	Tags: <a href="http://www.webresourcesdepot.com/tag/javascript/" title="Javascript" rel="tag">Javascript</a>, <a href="http://www.webresourcesdepot.com/tag/mysql/" title="Mysql" rel="tag">Mysql</a>, <a href="http://www.webresourcesdepot.com/tag/php/" title="Php" rel="tag">Php</a><br />

	<h4>Related posts</h4>
	<ul class='st-related-posts'>
	<li><a href="http://www.webresourcesdepot.com/testswarm-continious-distributed-js-testing/" title="TestSwarm: Continious &#038; Distributed JS Testing (August 27, 2009)">TestSwarm: Continious &#038; Distributed JS Testing</a></li>
	<li><a href="http://www.webresourcesdepot.com/php-shoutbox-script-wtag/" title="PHP Shoutbox Script: wTag (June 22, 2008)">PHP Shoutbox Script: wTag</a></li>
	<li><a href="http://www.webresourcesdepot.com/display-mysql-data-in-google-maps-using-drasticmap/" title="Display MySQL Data In Google Maps Using DrasticMap (February 27, 2008)">Display MySQL Data In Google Maps Using DrasticMap</a></li>
	<li><a href="http://www.webresourcesdepot.com/ajaxed-dragn-drop-shopping-cart-with-jquery-php/" title="Ajaxed Drag&#8217;n Drop Shopping Cart With jQuery &#038; PHP (September 20, 2009)">Ajaxed Drag&#8217;n Drop Shopping Cart With jQuery &#038; PHP</a></li>
	<li><a href="http://www.webresourcesdepot.com/ajax-star-rating-with-php-mysql/" title="Ajax Star Rating With PHP &#038; MySQL (January 19, 2009)">Ajax Star Rating With PHP &#038; MySQL</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/creating-a-slick-ajaxed-add-to-basket-with-jquery-and-php/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin Development &#8211; 10 Tutorials To Get Started</title>
		<link>http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-started/</link>
		<comments>http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-started/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 06:46:26 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[Extras]]></category>
		<category><![CDATA[Other License]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=848</guid>
		<description><![CDATA[jQuery, one of the most popular JavaScript library, has a huge selection of plugins which makes it more powerful.
On the other hand, there are much more codes/modules, from simple alert functions to complex galleries/form validation methods, that are hard-coded inside websites &#38; not converted to plugins.
For sure, not every code must become a plugin, that [...]]]></description>
			<content:encoded><![CDATA[<p><strong><img height="78" width="140" align="left" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-logo.gif" alt="jQuery Logo" style="margin-right: 5px;" />jQuery</strong>, one of the most popular JavaScript library, has a <a href="http://plugins.jquery.com/" target="_blank">huge selection of plugins</a> which makes it more powerful.</p>
<p>On the other hand, there are much more codes/modules, <strong>from simple alert functions to complex galleries/form validation methods</strong>, that are hard-coded inside websites &amp; not converted to plugins.</p>
<p>For sure, <strong>not every code must become a plugin</strong>, that would be meaningless. But converting the ones to be re-used will save a lot of re-development time &amp; if shared with the community, will make the code itself better.</p>
<p><strong>jQuery</strong> offers an easy to learn &amp; flexible environment for <strong>creating plugins</strong>. Here are <strong>10 tutorials to get you started</strong>:</p>
<div class="featured"><strong>You may also like:</strong> <a href="http://www.webresourcesdepot.com/9-free-and-open-source-bug-tracking-softwares/">9 Free And Open Source Bug Tracking Softwares</a>.</div>
<p>&nbsp;</p>
<h3><a href="http://james.padolsey.com/javascript/why-create-a-jquery-plugin/" target="_blank">Why Create A jQuery Plugin?</a></h3>
<p><a href="http://james.padolsey.com/javascript/why-create-a-jquery-plugin/" target="_blank"><img height="128" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/create-a-jquery-plugin.gif" alt="Why Create A jQuery Plugin" /></a></p>
<p>James Padolsey discusses the need &amp; reasons for <strong>creating a jQuery plugin</strong>.</p>
<p>He clearly puts of the advantages provided like portability, time to be gained &amp; more.&nbsp;</p>
<h3><a href="http://docs.jquery.com/Plugins/Authoring" target="_blank">Plugins/Authoring From jQuery.com</a></h3>
<p><a target="_blank" href="http://docs.jquery.com/Plugins/Authoring"><img height="128" width="480" alt="jQuery Plugin Tutorial" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-tutorial.gif" /></a></p>
<p>The first stop for everyone planning to <strong>create a jQuery plugin</strong>.</p>
<p>It covers the logic, naming patterns &amp; steps like:</p>
<ul>
<li class="toclevel-1"><span class="toctext">Collecting static functions in objects</span></li>
<li class="toclevel-1"><span class="toctext">Options</span></li>
<li class="toclevel-1"><span class="toctext">Customizing animations</span></li>
</ul>
<h3><a href="http://snook.ca/archives/javascript/jquery_plugin/" target="_blank">Developing A jQuery Plugin</a></h3>
<p><a href="http://snook.ca/archives/javascript/jquery_plugin/" target="_blank"><img height="164" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/develop-jquery-plugin.jpg" alt="Develop jQuery Plugin" /></a></p>
<p>Jonathan Snook is sharing his thoughts on <strong>developing a jQuery plugin</strong>.</p>
<p>A quick look to the basics &amp; advantages of &quot;why we need a plugin&quot;.</p>
<p><span id="more-848"></span></p>
<h3><a href="http://www.authenticsociety.com/blog/jQueryPluginTutorial_Beginner" target="_blank">jQuery Plugin Tutorial, In-Depth For Absolute Beginners</a></h3>
<p><a href="http://www.authenticsociety.com/blog/jQueryPluginTutorial_Beginner" target="_blank"><img height="128" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-tut.gif" alt="jQuery Create Plugin Tutorial" /></a></p>
<p>A tutorial for absolute beginners, including fresh JavaScript developers.</p>
<p>It clearly shows the advantages of jQuery &amp; creates a simple plugin named &quot;Shuffle&quot; by describing every step in detail.</p>
<h3><a href="http://webcloud.se/article/Building_jQuery_plugins" target="_blank">Building jQuery Plugins</a></h3>
<p><a href="http://webcloud.se/article/Building_jQuery_plugins" target="_blank"><img height="164" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-dev.jpg" alt="Building jQuery Plugins" /></a></p>
<p>A tutorial for creating 2 different plugins:</p>
<ul>
<li><strong>jQuery.tabify</strong>: for creating tabbed contents easily</li>
<li><strong>jQuery.lessMore</strong>: a plugin that can hide any number of childs of a given parent object</li>
</ul>
<h3><a target="_blank" href="http://nettuts.com/tutorials/javascript-ajax/the-definitive-guide-to-creating-a-practical-jquery-plugin/">The Definitive Guide to Creating a Practical jQuery Plugin</a></h3>
<p><a target="_blank" href="http://nettuts.com/tutorials/javascript-ajax/the-definitive-guide-to-creating-a-practical-jquery-plugin/"><img height="128" width="480" alt="Create jQuery Plugin Guide" src="http://www.webresourcesdepot.com/wp-content/uploads/image/create-jquery-plugin.jpg" /></a></p>
<p>NETTUTS shows the <strong>steps of a jQuery plugin development</strong> by creating a simple image loader plugin.</p>
<p>The plugin loads the images at the backstage, they are saved in the visitor&rsquo;s browser cache, so, they will be usable throughout the rest of the site.</p>
<h3><a target="_blank" href="http://yensdesign.com/2008/12/how-to-create-a-plugin-for-jquery/">How To Create A Plugin For jQuery</a></h3>
<p><a target="_blank" href="http://yensdesign.com/2008/12/how-to-create-a-plugin-for-jquery/"><img height="164" width="480" alt="How To Build A jQuery Plugin" src="http://www.webresourcesdepot.com/wp-content/uploads/image/how-to-build-jquery-plugin.jpg" /></a></p>
<p>yensdesign describes the basics needed like the difference between <code>jQuery</code> &amp; <code>jQuery.fn</code> objects. Then creates an input highlighter plugin.</p>
<h3><a href="http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html" target="_blank">Building Your First jQuery Plugin</a></h3>
<p><a href="http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html" target="_blank"><img height="128" width="480" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-basics.gif" alt="jQuery Plugin Basics" /></a></p>
<p>This is the tutorial for creating the <a href="http://jmar777.blogspot.com/2008/02/jtruncate-text-truncation-for-jquery.html" target="_blank">jTruncate plugin</a>, a well-known plugin for truncating text.</p>
<p>It includes tips like using <code>jQuery</code> rather than <code>$</code>, usage of <code>extend</code> method &amp; more. At the end of the tutorial, you&#8217;ll be created a fully-functional plugin.</p>
<h3><a target="_blank" href="http://nettuts.com/javascript-ajax/learn-how-to-create-a-jquery-plugin/">Learn How to Create a jQuery Plugin</a></h3>
<p><a target="_blank" href="http://nettuts.com/javascript-ajax/learn-how-to-create-a-jquery-plugin/"><img height="128" width="480" alt="How To Create A jQuery Plugin" src="http://www.webresourcesdepot.com/wp-content/uploads/image/how-to-create-jquery-plugin.jpg" /></a></p>
<p>A step-by-step <strong>tutorial on creating a jQuery plugin</strong> that dynamically adjusts the styling of a specified element for always keeping it vertically and horizontally centered on the page.</p>
<p>The tutorial is supported with a screencast as well.</p>
<h3><a target="_blank" href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern">A Plugin Development Pattern</a></h3>
<p><a target="_blank" href="http://www.learningjquery.com/2007/10/a-plugin-development-pattern"><img height="128" width="480" alt="jQuery Plugin Development" src="http://www.webresourcesdepot.com/wp-content/uploads/image/jquery-plugin-development.gif" /></a></p>
<p>Karl Swedberg, a developer who already created several plugins, is sharing his experiences for a better <strong>jQuery plugin development</strong> process.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a><br />
<a href="http://twitter.com/umutm" target="_blank">Follow WebResourcesDepot At Twitter And Get More Resources!</a></p>

	Tags: <a href="http://www.webresourcesdepot.com/tag/javascript/" title="Javascript" rel="tag">Javascript</a><br />

	<h4>Related posts</h4>
	<ul class='st-related-posts'>
	<li><a href="http://www.webresourcesdepot.com/zoom-script-with-a-smart-interface-tjpzoom/" title="Zoom Script With A Smart Interface: TJPzoom (September 4, 2008)">Zoom Script With A Smart Interface: TJPzoom</a></li>
	<li><a href="http://www.webresourcesdepot.com/yui-slideshow-customizable-and-animated-slideshows/" title="YUI Slideshow: Customizable And Animated Slideshows (August 12, 2009)">YUI Slideshow: Customizable And Animated Slideshows</a></li>
	<li><a href="http://www.webresourcesdepot.com/what-you-see-is-what-you-ajax-wavemaker/" title="What You See Is What You Ajax: WaveMaker (March 5, 2008)">What You See Is What You Ajax: WaveMaker</a></li>
	<li><a href="http://www.webresourcesdepot.com/wforms-easy-javascript-form-controls/" title="wForms: Easy JavaScript Form Controls (April 25, 2008)">wForms: Easy JavaScript Form Controls</a></li>
	<li><a href="http://www.webresourcesdepot.com/web-based-ftp-client-similar-to-windows-explorer/" title="Web Based FTP Client Similar To Windows Explorer (February 22, 2008)">Web Based FTP Client Similar To Windows Explorer</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/jquery-plugin-development-10-tutorials-to-get-started/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sliding Top Menu With jQuery</title>
		<link>http://www.webresourcesdepot.com/sliding-top-menu-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/sliding-top-menu-with-jquery/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 05:01:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Extras]]></category>
		<category><![CDATA[Goodies]]></category>
		<category><![CDATA[License Free]]></category>
		<category><![CDATA[Menu & Navigation]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=341</guid>
		<description><![CDATA[Sliding menus are very effective in areas where we have limited space .
This is a sliding top menu built with jQuery which can be fired through the open &#38; close buttons or with any tag with the related class name.
You can also use it as an info box, login area &#38; more.
Click here to see [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Sliding menus</strong> are very effective in areas where we have limited space .</p>
<p>This is a <strong>sliding top menu built with jQuery</strong> which can be fired through the open &amp; close buttons or with any tag with the related class name.</p>
<p>You can also use it as an info box, login area &amp; more.</p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/jquery-sliding-menu" target="_blank">Click here to see the final working demo of this <strong>jQuery sliding menu</strong></a>.</p>
<h3>It presents the menu when closed like this:</h3>
<p><img width="480" height="40" alt="Sliding Top Menu" src="http://www.webresourcesdepot.com/wp-content/uploads/sliding-top-menu.jpg" /></p>
<h3>And when opened:</h3>
<p><img width="480" height="150" alt="jQuery Sliding Menu" src="http://www.webresourcesdepot.com/wp-content/uploads/jquery-sliding-menu.jpg" /></p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/jquery-sliding-menu.zip"><img width="150" height="70" align="left" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download.jpg" alt="Downloa jQuery Sliding Menu" style="margin-right: 5px;" /></a></p>
<p>&nbsp;</p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/jquery-sliding-menu" target="_blank">Click here to see the final working demo of this jQuery sliding menu</a>.</p>
<p>&nbsp;</p>
<h3>Step 1 &#8211; HTML:</h3>
<p><code>&lt;div id=&quot;sliderWrap&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;div id=&quot;openCloseIdentifier&quot;&gt;&lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;div id=&quot;slider&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id=&quot;sliderContent&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Isn't this nice?<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id=&quot;openCloseWrap&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;a href=&quot;#&quot; class=&quot;topMenuAction&quot; id=&quot;topMenuImage&quot;&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;img src=&quot;open.png&quot; alt=&quot;open&quot; /&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/a&gt;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&nbsp;&nbsp;&nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</code><br />
&nbsp;</p>
<h3>Step 2 &#8211; CSS:</h3>
<p><code>&lt;style type=&quot;text/css&quot;&gt;<br />
body {<br />
margin: 0;<br />
font-size:16px;<br />
color: #000000;<br />
font-family:Arial, Helvetica, sans-serif;<br />
}<br />
#sliderWrap {<br />
margin: 0 auto;<br />
width: 300px;<br />
}<br />
#slider {<br />
position: absolute;<br />
background-image:url(slider.png);<br />
background-repeat:no-repeat;<br />
background-position: bottom;<br />
width: 300px;<br />
height: 159px;<br />
margin-top: -141px;<br />
}<br />
#slider img {<br />
border: 0;<br />
}<br />
#sliderContent {<br />
margin: 50px 0 0 50px;<br />
position: absolute;<br />
text-align:center;<br />
background-color:#FFFFCC;<br />
color:#333333;<br />
font-weight:bold;<br />
padding: 10px;<br />
}<br />
#header {<br />
margin: 0 auto;<br />
width: 600px;<br />
background-color: #F0F0F0;<br />
height: 200px;<br />
padding: 10px;<br />
}<br />
#openCloseWrap {<br />
position:absolute;<br />
margin: 143px 0 0 120px;<br />
font-size:12px;<br />
font-weight:bold;<br />
}<br />
&lt;/style&gt;</code><br />
&nbsp;</p>
<p>With the CSS file there are few major points:</p>
<ul>
<li>#slider has to be positioned absolutely, so it can overlay the other content.</li>
<li>#slider has a negative top-margin which hides it.</li>
<li>#sliderContent is positioned absolutely to not to crack the open/close buttons</li>
<li>#openCloseWrap holding the buttons are positioned absolutely too.</li>
</ul>
<h3>Step 3 &#8211; jQuery / JavaScript:</h3>
<p><code>&lt;script type=&quot;text/javascript&quot;&gt;<br />
$(document).ready(function() {<br />
&nbsp;&nbsp;&nbsp; $(&quot;.topMenuAction&quot;).click( function() {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($(&quot;#openCloseIdentifier&quot;).is(&quot;:hidden&quot;)) {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#slider&quot;).animate({ <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; marginTop: &quot;-141px&quot;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }, 500 );<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#topMenuImage&quot;).html('&lt;img src=&quot;open.png&quot;/&gt;');<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#openCloseIdentifier&quot;).show();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } else {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#slider&quot;).animate({ <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; marginTop: &quot;0px&quot;<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }, 500 );<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#topMenuImage&quot;).html('&lt;img src=&quot;close.png&quot;/&gt;');<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;#openCloseIdentifier&quot;).hide();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; });&nbsp; <br />
});<br />
&lt;/script&gt; </code></p>
<p>The main trick is changing the top margin of <code>#slider</code> and update the open / close images.</p>
<p>We have an empty element named <code>openCloseIdentifier</code> which shows us whether the menu is open or closed. We simply hide it when the menu is open and show when it is closed.</p>
<p><strong>Then all we do is:</strong></p>
<p>if <code>openCloseIdentifier = hidden</code> then close the menu or <code>if openCloseIdentifier = visible</code> then open the menu.</p>
<p><strong>Sliding effect</strong> can be fastened by changing the 500 value in <strong>JavaScript</strong> to a smaller number or else.</p>
<p>P.S. Down &amp; up arrow icons are from the <a target="_blank" href="http://www.everaldo.com/crystal/">Crystal Clear</a> icon set.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a><br />
<a href="http://twitter.com/umutm" target="_blank">Follow WebResourcesDepot At Twitter And Get More Resources!</a></p>

	Tags: <a href="http://www.webresourcesdepot.com/tag/jquery/" title="jQuery" rel="tag">jQuery</a><br />

	<h4>Related posts</h4>
	<ul class='st-related-posts'>
	<li><a href="http://www.webresourcesdepot.com/winners-of-the-flowplayer-contest/" title="Winners Of The Flowplayer Contest (January 8, 2009)">Winners Of The Flowplayer Contest</a></li>
	<li><a href="http://www.webresourcesdepot.com/table-sorter-plugin-for-jquery-tablesorter/" title="Table Sorter Plugin For jQuery: tablesorter (May 14, 2008)">Table Sorter Plugin For jQuery: tablesorter</a></li>
	<li><a href="http://www.webresourcesdepot.com/tabbed-content-area-with-jquery-and-css/" title="Tabbed Content Area With jQuery And CSS (May 13, 2008)">Tabbed Content Area With jQuery And CSS</a></li>
	<li><a href="http://www.webresourcesdepot.com/smart-floating-banners/" title="Smart Floating Banners (June 23, 2008)">Smart Floating Banners</a></li>
	<li><a href="http://www.webresourcesdepot.com/slideshow-js-unobtrusive-javascript-slideshow/" title="Slideshow JS: Unobtrusive JavaScript Slideshow (May 16, 2009)">Slideshow JS: Unobtrusive JavaScript Slideshow</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/sliding-top-menu-with-jquery/feed/</wfw:commentRss>
		<slash:comments>75</slash:comments>
		</item>
		<item>
		<title>Load Content While Scrolling With jQuery</title>
		<link>http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/</link>
		<comments>http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 05:01:40 +0000</pubDate>
		<dc:creator>Umut M.</dc:creator>
				<category><![CDATA[Browsing]]></category>
		<category><![CDATA[CC License]]></category>
		<category><![CDATA[Extras]]></category>
		<category><![CDATA[Goodies]]></category>
		<category><![CDATA[License Free]]></category>
		<category><![CDATA[MIT License]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Scroll]]></category>

		<guid isPermaLink="false">http://www.webresourcesdepot.com/?p=327</guid>
		<description><![CDATA[We generally have lots of content to present but can not load all of it at once as it may take too long.
I always loved the dZone&#8217;s Ajax content loading while scrolling feature and created a similar one using jQuery.
I&#8217;m pleased to share with WebResourcesDepot readers (Check the demo &#8211; scroll down to see new [...]]]></description>
			<content:encoded><![CDATA[<p>We generally have lots of content to present but can not load all of it at once as it may take too long.</p>
<p>I always loved the <strong>dZone&#8217;s Ajax content loading while scrolling</strong> feature and created a similar one using <strong>jQuery.</strong></p>
<p>I&#8217;m pleased to share with <strong>WebResourcesDepot</strong> readers (<a href="http://www.webresourcesdepot.com/dnspinger/" target="_blank"><strong>Check the demo</strong></a> &#8211; scroll down to see new content in the demo)</p>
<p>This <strong>Ajax auto content loading</strong> can very be handy in almost every project. <span style="font-weight: bold;">D</span><strong>on&#8217;t forget to bookmark it (<a target="_blank" href="http://del.icio.us/webresourcesdepot?url=http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery-tutorial%2F&amp;title=Load Content While Scrolling With jQuery">del.icio.us link</a>)</strong>.</p>
<p><a target="_blank" href="http://www.webresourcesdepot.com/dnspinger"><img width="480" height="84" alt="jQuery Load Content While Scrolling" src="http://www.webresourcesdepot.com/wp-content/uploads/jquery-content-scroller.gif" /></a></p>
<p><a href="http://www.webresourcesdepot.com/wp-content/uploads/file/wrd-scroll.zip" target="_blank"><img width="150" height="70" align="left" style="margin-right: 10px;" src="http://www.webresourcesdepot.com/wp-content/uploads/image/download.jpg" alt="Download Load Content While Scrolling With jQuery" /></a></p>
<p>
Download package includes a working demo coded with ASP with a test MySQL database. ASP code is just a simple query so you can switch it with a one you like easily.</p>
<p>&nbsp;</p>
<p><span id="more-327"></span></p>
<h3>What is loading content while scrolling?</h3>
<p>When we are <strong>scrolling</strong> down a webpage, the code recognizes that you are at the bottom and <strong>auto-loads new content</strong>.</p>
<h3>Why to use it?</h3>
<p>It helps increasing the initial load speeds of pages faster and users will have to load only the content they see.</p>
<h3>How it works? (<a target="_blank" href="http://www.webresourcesdepot.com/dnspinger/">Check the demo</a>)</h3>
<p>In our case, we have DIVS holding contents where every DIV ID is content&#8217;s database ID.</p>
<ul>
<li>Content structure is like:</li>
</ul>
<p><code>&lt;div class=&quot;wrdLatest&quot; id=9&gt;content&lt;/div&gt;<br />
&lt;div </code><code>class</code><code>=&quot;wrdLatest&quot; id=8&gt;content&lt;/div&gt;</code></p>
<ul>
<li>We create a function sending a query to a dynamic file with the DIV ID of the latest wrdLatest DIV (and also put a loader image):</li>
</ul>
<p style="text-align: left;"><code>function lastPostFunc() <br />
{ <br />
&nbsp;&nbsp;&nbsp; $('div#lastPostsLoader').html('&lt;img src=&quot;bigLoader.gif&quot;&gt;');<br />
&nbsp;&nbsp;&nbsp; $.post(&quot;scroll.asp?action=getLastPosts&amp;lastID=&quot; + $(&quot;.wrdLatest:last&quot;).attr(&quot;id&quot;), </code> <code> &nbsp;&nbsp;&nbsp; <br />
</code></p>
<p style="text-align: left;"><code>&nbsp;&nbsp;&nbsp; function(data){<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (data != &quot;&quot;) {<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $(&quot;.wrdLatest:last&quot;).after(data);&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $('div#lastPostsLoader').empty();<br />
&nbsp;&nbsp;&nbsp; });<br />
};&nbsp;<br />
</code></p>
<ul>
<li>When a user <strong>scrolls down</strong>, we understand that the scroller is at the bottom with teh function below and fire the <code>lastPostFunc</code> function.</li>
</ul>
<p><code>$(window).scroll(function(){<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if&nbsp; ($(window).scrollTop() == $(document).height() - $(window).height()){<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; lastPostFunc();<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
}); </code></p>
<p>I have <a target="_blank" href="http://www.webresourcesdepot.com/dnspinger/">applied the demo to the DNSPinger service</a>. Simply scroll down to see new content loading.</p>
<h3>Dependencies</h3>
<p><strike>This is a very simple code that uses <strong>jQuery&#8217;s</strong> great </strike><a target="_blank" href="http://brandonaaron.net/docs/dimensions/"><strike><strong>dimensions plugin</strong></strike></a><strike> that helps us understand that we are at the bottom of the page.</strike> <strong>Update: Dimensions plugin</strong> is included with <strong>jQuery</strong> 1.2.6 and no need to include it as an extra.</p>
<p>Besides that, you can improve the code to detect the users sceen-size and load your initial content according to that screen size.</p>
<p><strong>Special Downloads:</strong><br />
<a href="http://www.webresourcesdepot.com/?download=jBasket" target="_blank">Ajaxed Add-To-Basket Scenarios With jQuery And PHP</a><br />
<a href="http://www.webresourcesdepot.com/?download=Free-Admin-Template" target="_blank">Free Admin Template For Web Applications</a><br />
<a href="http://www.webresourcesdepot.com/?download=jQuery-Dynamic-Drag-Drop" target="_blank">jQuery Dynamic Drag&#8217;n Drop</a><br />
<a href="http://www.webresourcesdepot.com/?download=sTwitter-1-0" target="_blank">ScheduledTweets</a></p>
<p><strong>Advertisements:</strong><br />
<a href="http://www.sslmatic.com" target="_blank">SSLmatic &#8211; Cheap SSL Certificates (from $19.99/year)</a><br />
<a href="http://twitter.com/umutm" target="_blank">Follow WebResourcesDepot At Twitter And Get More Resources!</a></p>

	Tags: <a href="http://www.webresourcesdepot.com/tag/javascript/" title="Javascript" rel="tag">Javascript</a>, <a href="http://www.webresourcesdepot.com/tag/jquery/" title="jQuery" rel="tag">jQuery</a>, <a href="http://www.webresourcesdepot.com/tag/scroll/" title="Scroll" rel="tag">Scroll</a><br />

	<h4>Related posts</h4>
	<ul class='st-related-posts'>
	<li><a href="http://www.webresourcesdepot.com/table-sorter-plugin-for-jquery-tablesorter/" title="Table Sorter Plugin For jQuery: tablesorter (May 14, 2008)">Table Sorter Plugin For jQuery: tablesorter</a></li>
	<li><a href="http://www.webresourcesdepot.com/smart-floating-banners/" title="Smart Floating Banners (June 23, 2008)">Smart Floating Banners</a></li>
	<li><a href="http://www.webresourcesdepot.com/slideshow-js-unobtrusive-javascript-slideshow/" title="Slideshow JS: Unobtrusive JavaScript Slideshow (May 16, 2009)">Slideshow JS: Unobtrusive JavaScript Slideshow</a></li>
	<li><a href="http://www.webresourcesdepot.com/skin-your-ajax-applications-themeroller/" title="Skin Your Ajax Applications: ThemeRoller (June 10, 2008)">Skin Your Ajax Applications: ThemeRoller</a></li>
	<li><a href="http://www.webresourcesdepot.com/rounded-corners-with-no-images-using-curvycorners/" title="Rounded Corners With No Images Using curvyCorners (December 30, 2007)">Rounded Corners With No Images Using curvyCorners</a></li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.webresourcesdepot.com/load-content-while-scrolling-with-jquery/feed/</wfw:commentRss>
		<slash:comments>90</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 2.697 seconds -->
