100 likes | 251 Views
More jQuery. Professor Josh Miller Lehigh university | fall 2010. Writing your own…. As always, you must link to the jquery javascript file- or link to the live version online <script src =" http://code.jquery.com/jquery-latest.min.js "></script >
E N D
More jQuery Professor Josh Miller Lehigh university | fall 2010
Writing your own… • As always, you must link to the jqueryjavascript file- or link to the live version online <script src="http://code.jquery.com/jquery-latest.min.js"></script> • Your code can go in the head section or in an external js file (linked the same was as above) <head> <script type="text/javascript"> $(document).ready(function() { // your code goes here… by the way // means a comment- a note to yourself }); </script> </head>
Code linked to document.ready… <script type="text/javascript"> $(document).ready(function() { alert("hello"); }); </script>
Redefine a click action… <script type="text/javascript"> $(document).ready(function() { $('a#hideDiv').click(function() { $('#redDiv').hide(1000); return false; }); }); </script> Line 4: redefines the click action for links (a) with the id (#) of hideDiv Line 5 : hides the visibility of the div with the id (#) redDiv, animation takes 1000 ms to complete 1 2 3 4 5 6
Redefine a click action… <script type="text/javascript"> $(document).ready(function() { $('a#hideDiv').click(function() { $('#redDiv').toggle(1000); return false; }); }); </script> Line 4: redefines the click action for links (a) with the id (#) of hideDiv Line 5 : toggles the visibility of the div with the id (#) redDiv 1 2 3 4 5 6
Redefine a click action… $('#clickme').click(function() { $('#puppy').hide(1000); return false; }); … <div id="clickme"> Click here </div> <img id=”puppy" src=”adorablepuppy.jpg” />
Mootools accordion • (easier to implement than jquery solutions, but doesn’t play nicely with jquery libraries) • http://demos.mootools.net/Accordion • Link to the js & css, modify code in both to customize • Implementation: <div id="accordion"> <h3 class="toggler">title</h3> title of menu option <div class="element"> … content inside slider here </div> </div>
Mootoolsfx.slide • http://demos.mootools.net/Fx.Slide • Link to js & css- must modify js to use subset of functionality • For example to use only toggle, your js file only needs to include window.addEvent('domready', function() { varmyVerticalSlide = new Fx.Slide('vertical_slide'); $('v_toggle').addEvent('click', function(e){ e.stop(); myVerticalSlide.toggle(); }); });
AnythingSlider • http://css-tricks.com/anythingslider-jquery-plugin/ • Btw, are you reading css tricks every day? You should. And smashing magazine. • Link to the js & css • Implementation: <div class="anythingSlider"> <div class="wrapper"> <ul> <li> … content of slide </li> <li> … content of slide </li> </ul> </div> </div>
What now? • Well, I’m not going to teach you anymore jQuery… • You should be able to apply the gallery & content slider examples to any library you need to implement • Here’s an incredibly useful resource • http://jqueryfordesigners.com/