{"id":506,"date":"2015-03-03T12:05:57","date_gmt":"2015-03-03T19:05:57","guid":{"rendered":"https:\/\/rmu.andrewyames.com\/?page_id=506"},"modified":"2015-03-03T12:05:57","modified_gmt":"2015-03-03T19:05:57","slug":"week-8-jquery-plugin-basics","status":"publish","type":"page","link":"https:\/\/rmu.andrewyames.com\/?page_id=506","title":{"rendered":"Week 8: jQuery Plugin Basics"},"content":{"rendered":"<p><a href=\"http:\/\/jquery.com\/\" target=\"_blank\">jQuery<\/a> is a javascript library that simplifies the code designers and developers need to write for\u00a0 various types of interactivity, form validation and animation. It works in combination with your HTML and CSS, and generally is plug and play.<\/p>\n<p><strong>Download the main plugin: <a href=\"http:\/\/code.jquery.com\/jquery-1.7.2.min.js\" target=\"_blank\">jquery-1.7.2.min.js<\/a><\/strong><\/p>\n<p>The main library must be included inside the head of your html document using the script tag. You\u2019ll notice a few ways of doing this when looking at other peoples code, for example:<\/p>\n<p><span style=\"color: #993366;\"><strong>&lt;script\u00a0src=\u201dhttp:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.4.4\/jquery.min.js\u201d&gt;&lt;\/script&gt;<\/strong><\/span> this links to version 1.4.4 of the jquery plugin hosted on google\u2019s server.<\/p>\n<p><span style=\"color: #993366;\"><strong>&lt;script\u00a0\u00a0type=\u201dtext\/javascript\u201d src=\u201d_js\/jquery-1.7.2.min.js\u201d&gt;&lt;\/script&gt;<\/strong><\/span>this would link to the latest version of the jquery plugin inside a folder called _js which would be within the sites root directory. This tag also includes the type attribute which simply tells the browser that the script being used is javascript.<\/p>\n<p>With the main plugin attached to your html document you can then write your own simple functions or attach functions developed by others.<\/p>\n<p>For example if you also attach the UI plugin:<strong><br \/>\n<span style=\"color: #993366;\">&lt;script type=\u201dtext\/javascript\u201d src=\u201d_js\/jquery-ui.min.js\u201d&gt;&lt;\/script&gt;<\/span><\/strong><\/p>\n<p>You can then write a simple function to animate rollovers by switching between two classes<\/p>\n<p><span style=\"color: #993366;\"><strong>&lt;script type=\u201dtext\/javascript\u201d&gt;<\/strong><\/span><br \/>\n<span style=\"color: #00ccff;\"><strong>\u00a0 \u00a0$(document).ready(function(){<\/strong><\/span> \/\/ this waits for the document to finish loading before allowing any other function to run<\/p>\n<p><span style=\"color: #99cc00;\"><strong>\u00a0 \u00a0 \u00a0 $(\u201ca\u201d).mouseenter(buttonHover)<\/strong><\/span> \/\/ this tells the browser that when the mouse enters any &lt;a&gt; tag to run the function buttonHover.<br \/>\n<span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0function buttonHover(){<\/strong><\/span><br \/>\n<span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0$(this).switchClass(\u2018button\u2019,\u2019button_hover\u2019,500);<\/strong><\/span><br \/>\n<span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/strong><\/span> \/\/ this function switches the class button with buton_hover, over 500 milliseconds<br \/>\n<strong>\u00a0\u00a0 \u00a0<\/strong><br \/>\n<span style=\"color: #99cc00;\"><strong>\u00a0 \u00a0 \u00a0 $(\u201ca\u201d).mouseleave(button)<\/strong><\/span> \/\/ this tells the browser that when the mouse leaves any a tag to run the function button.<br \/>\n<span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0function button(){<\/strong><\/span><br \/>\n<span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0 \u00a0 \u00a0 $(this).switchClass(\u2018button_hover\u2019,\u2019button\u2019,500);<\/strong><\/span><br \/>\n<strong><span style=\"color: #ff9900;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span>\u00a0\u00a0\u00a0 <\/strong>\/\/ this function switches the class button_hover with button, over 500 milliseconds<br \/>\n<span style=\"color: #00ccff;\"><strong>\u00a0 \u00a0});<\/strong><\/span><br \/>\n<span style=\"color: #993366;\"><strong>&lt;\/script&gt;<\/strong><\/span><\/p>\n<p>For this to work you\u2019ll also need styles for your two button classes<\/p>\n<p><span style=\"color: #ff00ff;\"><strong>&lt;style&gt;<\/strong><\/span><\/p>\n<p><span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0.button {color:#ccc; background-color: #FFF;}<\/strong><\/span><\/p>\n<p><span style=\"color: #ff9900;\"><strong>\u00a0 \u00a0.button_hover {color:#666; background-color:#FDC758;}<\/strong><\/span><\/p>\n<p><span style=\"color: #ff00ff;\"><strong>&lt;\/style&gt;<\/strong><\/span><\/p>\n<p>And any of the links you want to have this effect applied would need to look like this<\/p>\n<p><strong>&lt;a href=\u201dSOMEFILE.html\u201d class=\u201dbutton\u201d&gt;Your Text&lt;\/a&gt;<\/strong><\/p>\n<h2>Useful Plugins<\/h2>\n<ul>\n<li>UI effects: <a href=\"http:\/\/jqueryui.com\/\" target=\"_blank\">http:\/\/jqueryui.com\/<\/a><\/li>\n<li>Easing effects:<a href=\"http:\/\/gsgd.co.uk\/sandbox\/jquery\/easing\/\" target=\"_blank\">http:\/\/gsgd.co.uk\/sandbox\/jquery\/easing\/<\/a><\/li>\n<li>Auto scrolling:<a href=\"http:\/\/flesler.blogspot.com\/2007\/10\/jquerylocalscroll-10.html\" target=\"_blank\">http:\/\/flesler.blogspot.com\/2007\/10\/jquerylocalscroll-10.html<\/a><\/li>\n<li>Masonry effect:<a href=\"http:\/\/masonry.desandro.com\/\" target=\"_blank\">http:\/\/masonry.desandro.com\/<\/a><\/li>\n<li>Animated background effect:<a href=\"http:\/\/blog.themeforest.net\/tutorials\/create-a-funky-parallax-background-effect-using-jquery\/\" target=\"_blank\">http:\/\/blog.themeforest.net\/tutorials\/create-a-funky-parallax-background-effect-using-jquery\/<\/a><\/li>\n<li>Puffing smoke effect:<a href=\"http:\/\/www.gayadesign.com\/diy\/puffing-smoke-effect-in-jquery\/\" target=\"_blank\">http:\/\/www.gayadesign.com\/diy\/puffing-smoke-effect-in-jquery\/<\/a><\/li>\n<li>Shake effect:<a href=\"http:\/\/davidwalsh.name\/jquery-shake\" target=\"_blank\">http:\/\/davidwalsh.name\/jquery-shake<\/a><\/li>\n<li>A best of 2011 plug in set:<a href=\"http:\/\/www.smashingapps.com\/2011\/12\/26\/best-of-2011-best-useful-jquery-plugins-and-tutorials.html\" target=\"_blank\">http:\/\/www.smashingapps.com\/2011\/12\/26\/best-of-2011-best-useful-jquery-plugins-and-tutorials.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>jQuery is a javascript library that simplifies the code designers and developers need to write for\u00a0 various types of interactivity, form validation and animation. It works in combination with your HTML and CSS, and generally is plug and play. Download the main plugin: jquery-1.7.2.min.js The main library must be included inside the head of your &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rmu.andrewyames.com\/?page_id=506\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Week 8: jQuery Plugin Basics&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":27,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-506","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/pages\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=506"}],"version-history":[{"count":1,"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/pages\/506\/revisions"}],"predecessor-version":[{"id":507,"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/pages\/506\/revisions\/507"}],"up":[{"embeddable":true,"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=\/wp\/v2\/pages\/27"}],"wp:attachment":[{"href":"https:\/\/rmu.andrewyames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}