SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
Using jQuery
         to Extend CSS
             • Fix Cross Browser Problems
               • Solve CSS Shortcomings
               • Do Things CSS Can’t Do
             • Solve ‘Real World’ Problems
• Get Your Site into an Environment with a Bright Future
Why jQuery?




• What about MooTools? Prototype? (go for it!)
Transparency
With CSS:
.transparent_class {

    /* IE 8 */
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";

    /* IE 5-7 */
    filter: alpha(opacity=50);

    /* Netscape */
    -moz-opacity: 0.5;

    /* Safari 1.x */
    -khtml-opacity: 0.5;

    /* Good browsers */
    opacity: 0.5;
}




• Messy
• Invalid
Transparency
With jQuery:
$(“.transparent_class”).css(“opacity”, “0.5”);




• Clean
• Valid
Hover
With CSS:
div {
   background: white;
}

div:hover {
   background: #eee;
}



• Not supported in IE <= 6
• Limited...
Hover
With jQuery
$(“div”).hover(function(){
    $(this).addClass(“hover”);
}, function(){
    $(this).removeClass(“hover”);
});




• All Browser Support
• More Options
$(“div”).hover(function(){
    $(this).addClass(“hover bookHighlight”);
}, function(){
    $(this).removeClass(“hover bookHighlight”);
});
Attribute & Psuedo Selectors
HTML
 <input   type=”text” ... />       <ul>
 <input   type=”radio” ... />        <li><a href=”#”>List Item One</a></li>
 <input   type=”submit” ... />       <li><a href=”#”>List Item Two</a></li>
 <input   type=”checkbox” ... />     <li><a href=”#”>List Item Three</a></li>
 <input   type=”password” ... />   </ul>




CSS
 input[type=text] {                ul li {
    width: 250px;                     border-bottom: 1px solid #ccc;
    border: 1px solid #ccc;        }
    padding: 3px;
 }                                 ul li:last-child {
                                      border-bottom: 0;
 input[type=radio] {               }
    vertical-align: middle;
 }




• Not supported in IE <= 6
Attribute & Psuedo Selectors
With jQuery
 $(“input[type=text]”)          $(“ul li:last-child”)
    .addClass(“textInput”);        .addClass(“last”);



(Still handle styling with CSS)

 <form>                         $(“input[type=text]”)
    <div>                          .focus(function(){
        <label>Name</label>            $(this).parent().addClass(“formFocus”);
        <input type=”text” />      })
    </div>                         .blur(function(){
    <div>                              $(this).parent().removeClass(“formFocus”);
        <label>Email</label>       });
        <input type=”text” />
    </div>
    ...
Looks Simple?
                                            Grids are hard
                                             ...when not
                                             tabular data.
                                            ...and especially
                                            with variable
                                            height content


                                            Div has a hover state
                                            ...with opacity change
                                            ...and is a link.




   Need right margin   Doesn’t need right margin
Looks Simple?
HTML
<div class="book">
    <h3>Book Title</h3>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac
turpis egestas.</p>
    <a href="http://google.com">Learn More</a>
</div>




CSS
.book {
   width: 120px;
   float: left;
   padding: 10px;
   border: 1px solid #ccc;
   margin: 0 10px 10px 0;
}
Looks Simple?
$(function() {


$(".book:nth-child(4n+1)").css("margin-right","0px");


$(".book a").hide();


var maxHeight = 0;

$(".book").each(function(){

    
if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }

    
$(this).css("opacity", "0.7");

});

$(".book").height(maxHeight);

      $(".book").hover(function(){

    $(this)

     
    
.addClass("hover")

     
    
.css("opacity", "1.0");

}, function(){

    $(this)

     
    
.removeClass("hover")

     
    
.css("opacity", "0.7");

});


    $(".book").click(function(){

    
window.location = $(this).find("a").attr("href");

});

});
Looks Simple?
$(function() {


$(".book:nth-child(4n+1)").css("margin-right","0px");


$(".book a").hide();


var maxHeight = 0;

var books = $(".book");

    

books

    
.each(function() {

    
     
if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }

    
     
$(this).css("opacity", "0.7");

    
})

    

    
.height(maxHeight)

    
     

    
.hover(function() {

    
    $(this)

    
     
    
.addClass("hover")

    
     
    
.css("opacity", "1.0");

    
}, function() {

    
    $(this)

    
     
    
.removeClass("hover")

    
     
    
.css("opacity", "0.7");

    
})

    

    
.click(function() {

    
     
window.location = $(this).find("a").attr("href");

    
});
});
Table Tricks




• Zebra Striping
• Row / Column Highlighting
Table Tricks
$(function() {

      $("tr:odd").addClass("odd");

      var i = 0;
      $("colgroup").each(function() {
          i++;
          $(this).attr("id", "col"+i);
      });
      var totalCols = i;

      i = 1;
      $("td")
            .each(function() {
          
 $(this).attr("rel", "col"+i);

           i++;

           if (i > totalCols) { i = 1; }

      })

           .hover(function() {

                $(this).parent().addClass("hover");

      
         var curCol = $(this).attr("rel");

      
         $("#"+curCol).addClass("hover");

      
     }, function() {

      
         $(this).parent().removeClass("hover");

      
         var curCol = $(this).attr("rel");

      
         $("#"+curCol).removeClass("hover");

      
     });

});
Table Tricks
$(function() {


$("tr:contains('Hood')").addClass("found");

});
Table Tricks
Plugins!
Tablesorter 2.0 by Christian Bach
http://tablesorter.com/docs/
Animation is Easy




• It’s cool... but it’s flair.
• It’s (nearly) useless without JS.
Animation is Easy




$(function() {

      $("#page-wrap").append('<img src="/images/expando-tab.png" alt="" id="expando-tab" />');

      
    
    
      $('#expando').load('/expando.html');

      
      $("#expando-tab").click(function(){
          $("#expando").slideToggle();
      });

});
Animation is Easy
                                                          Regular State (overflow: hidden;)



                                                          Expanded State


var baseWidth = $("pre")[0].width(),
<pre><code>
    rightPadding here...
    ... code in = 10;
</code></pre>
$("pre").hover(function() {

var codeInnerWidth = $("code", this).width() + rightPadding;
     if (codeInnerWidth > baseWidth) {

pre 
$(this)
     {

 overflow: hidden;
     
    
.stop()

 width:
.css({
     
      563px;
}

    
    
    
zIndex: "100",

code
 { 
      
position: "relative"

 font-family: Courier, Monospace;
     
    
})
}

    
    
.animate({

    
    
    
width: codeInnerWidth + "px"

    
    
});

    
    }

}, function() {

    
    
$(this).stop().animate({

    
    
    
width: baseWidth

    
});

});
Loading after Loading


                 Big ass movie
                 Starts loading right away,
                 slows down page.

                  $(window).bind(“load”, function() {
                  
    
    
                    $('#movie-area').load('/movie.html');

                  });




                 Bonus
                 If users don’t have
                 JavaScript, the movie isn’t
                 going to play correctly
                 anyway. So nothing is shown.
Controlling Outside Content




                     Design is one thing...
                     Content is another. CSS was
                     able to control the new
                     graphics, but the change in
                     text was done with jQuery.
Controlling Outside Content




           $(function() {
           
    
    
             $('#coupon-link').text('Enter Voucher Code');

             $('#coupon-input').css('display', 'inline');

           });
MMMmmm Plugins
Facebox
http://famspam.com/facebox


Tablesorter
http://tablesorter.com/


Coda Slider
http://www.ndoherty.com/demos/coda-slider/1.1.1/


markItUp!
http://markitup.jaysalvat.com/home/



                                         jQuery UI
                                         http://jqueryui.com/


Interactions                 Widgets                  Effects
 •   Draggable               •   Accordion             •   Show/Hide Methods
 •   Droppable               •   Datepicker            •   Toggle Class
 •   Resizable               •   Dialog                •   Color Animation
 •   Selectable              •   Progressbar
 •   Sortable                •   Slider
                             •   Tabs
The FUTURE
            jQuery                                 CSS
                                            Dec. 17 1996 - CSS 1
                                            May 12 1998 - CSS 2

Jan.   14   2006   –   jQuery   Announced
Aug.   26   2006   -   jQuery   1.0
Jan.   14   2007   -   jQuery   1.1
                                            Jul. 19 2007 - CSS 2.1
Sep.   10   2007   -   jQuery   1.2
May    24   2008   -   jQuery   1.2.6
Feb.   20   2009   -   jQuery   1.3.2
                                            Apr. 23 2009 - CSS 2.1



                                            ???          - CSS 3



       Released Usable                      Recommendations
           Versions
The FUTURE
• Huge community of people USING it.
• Huge community of DEVELOPERS.
   • Loads of DOCUMENTATION.
   • Plenty of SUPPORT available.
    • Gosh darn it, people like it!

Más contenido relacionado

La actualidad más candente

jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery FundamentalsGil Fink
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutesSimon Willison
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETJames Johnson
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapHoward Lewis Ship
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebRobin Hawkes
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 

La actualidad más candente (20)

jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
Jquery ui
Jquery uiJquery ui
Jquery ui
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
The jQuery Divide
The jQuery DivideThe jQuery Divide
The jQuery Divide
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
jQuery
jQueryjQuery
jQuery
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
jQuery
jQueryjQuery
jQuery
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Jquery
JqueryJquery
Jquery
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 

Similar a Using jQuery to Extend CSS

jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Jack Franklin
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendFITC
 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)jeresig
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the WorldJonathan Snook
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricksambiescent
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)jeresig
 
JavaScript for Flex Devs
JavaScript for Flex DevsJavaScript for Flex Devs
JavaScript for Flex DevsAaronius
 
The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryQConLondon2008
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuerycolinbdclark
 
Jquery in-15-minutes1421
Jquery in-15-minutes1421Jquery in-15-minutes1421
Jquery in-15-minutes1421palsingh26
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQueryRemy Sharp
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue AdventureAllegient
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012ghnash
 

Similar a Using jQuery to Extend CSS (20)

jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the World
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
jQuery Loves You
jQuery Loves YoujQuery Loves You
jQuery Loves You
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
 
JQuery Flot
JQuery FlotJQuery Flot
JQuery Flot
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
 
JavaScript for Flex Devs
JavaScript for Flex DevsJavaScript for Flex Devs
JavaScript for Flex Devs
 
The Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J QueryThe Dom Scripting Toolkit J Query
The Dom Scripting Toolkit J Query
 
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
 
Jquery in-15-minutes1421
Jquery in-15-minutes1421Jquery in-15-minutes1421
Jquery in-15-minutes1421
 
Yearning jQuery
Yearning jQueryYearning jQuery
Yearning jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 

Último

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Último (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

Using jQuery to Extend CSS

  • 1. Using jQuery to Extend CSS • Fix Cross Browser Problems • Solve CSS Shortcomings • Do Things CSS Can’t Do • Solve ‘Real World’ Problems • Get Your Site into an Environment with a Bright Future
  • 2. Why jQuery? • What about MooTools? Prototype? (go for it!)
  • 3. Transparency With CSS: .transparent_class { /* IE 8 */ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* IE 5-7 */ filter: alpha(opacity=50); /* Netscape */ -moz-opacity: 0.5; /* Safari 1.x */ -khtml-opacity: 0.5; /* Good browsers */ opacity: 0.5; } • Messy • Invalid
  • 5. Hover With CSS: div { background: white; } div:hover { background: #eee; } • Not supported in IE <= 6 • Limited...
  • 6. Hover With jQuery $(“div”).hover(function(){ $(this).addClass(“hover”); }, function(){ $(this).removeClass(“hover”); }); • All Browser Support • More Options $(“div”).hover(function(){ $(this).addClass(“hover bookHighlight”); }, function(){ $(this).removeClass(“hover bookHighlight”); });
  • 7. Attribute & Psuedo Selectors HTML <input type=”text” ... /> <ul> <input type=”radio” ... /> <li><a href=”#”>List Item One</a></li> <input type=”submit” ... /> <li><a href=”#”>List Item Two</a></li> <input type=”checkbox” ... /> <li><a href=”#”>List Item Three</a></li> <input type=”password” ... /> </ul> CSS input[type=text] { ul li { width: 250px; border-bottom: 1px solid #ccc; border: 1px solid #ccc; } padding: 3px; } ul li:last-child { border-bottom: 0; input[type=radio] { } vertical-align: middle; } • Not supported in IE <= 6
  • 8. Attribute & Psuedo Selectors With jQuery $(“input[type=text]”) $(“ul li:last-child”) .addClass(“textInput”); .addClass(“last”); (Still handle styling with CSS) <form> $(“input[type=text]”) <div> .focus(function(){ <label>Name</label> $(this).parent().addClass(“formFocus”); <input type=”text” /> }) </div> .blur(function(){ <div> $(this).parent().removeClass(“formFocus”); <label>Email</label> }); <input type=”text” /> </div> ...
  • 9. Looks Simple? Grids are hard ...when not tabular data. ...and especially with variable height content Div has a hover state ...with opacity change ...and is a link. Need right margin Doesn’t need right margin
  • 10. Looks Simple? HTML <div class="book"> <h3>Book Title</h3> <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p> <a href="http://google.com">Learn More</a> </div> CSS .book { width: 120px; float: left; padding: 10px; border: 1px solid #ccc; margin: 0 10px 10px 0; }
  • 11. Looks Simple? $(function() { $(".book:nth-child(4n+1)").css("margin-right","0px"); $(".book a").hide(); var maxHeight = 0; $(".book").each(function(){ if ($(this).height() > maxHeight) { maxHeight = $(this).height(); } $(this).css("opacity", "0.7"); }); $(".book").height(maxHeight); $(".book").hover(function(){ $(this) .addClass("hover") .css("opacity", "1.0"); }, function(){ $(this) .removeClass("hover") .css("opacity", "0.7"); }); $(".book").click(function(){ window.location = $(this).find("a").attr("href"); }); });
  • 12. Looks Simple? $(function() { $(".book:nth-child(4n+1)").css("margin-right","0px"); $(".book a").hide(); var maxHeight = 0; var books = $(".book"); books .each(function() { if ($(this).height() > maxHeight) { maxHeight = $(this).height(); } $(this).css("opacity", "0.7"); }) .height(maxHeight) .hover(function() { $(this) .addClass("hover") .css("opacity", "1.0"); }, function() { $(this) .removeClass("hover") .css("opacity", "0.7"); }) .click(function() { window.location = $(this).find("a").attr("href"); }); });
  • 13. Table Tricks • Zebra Striping • Row / Column Highlighting
  • 14. Table Tricks $(function() { $("tr:odd").addClass("odd"); var i = 0; $("colgroup").each(function() { i++; $(this).attr("id", "col"+i); }); var totalCols = i; i = 1; $("td") .each(function() { $(this).attr("rel", "col"+i); i++; if (i > totalCols) { i = 1; } }) .hover(function() { $(this).parent().addClass("hover"); var curCol = $(this).attr("rel"); $("#"+curCol).addClass("hover"); }, function() { $(this).parent().removeClass("hover"); var curCol = $(this).attr("rel"); $("#"+curCol).removeClass("hover"); }); });
  • 16. Table Tricks Plugins! Tablesorter 2.0 by Christian Bach http://tablesorter.com/docs/
  • 17. Animation is Easy • It’s cool... but it’s flair. • It’s (nearly) useless without JS.
  • 18. Animation is Easy $(function() { $("#page-wrap").append('<img src="/images/expando-tab.png" alt="" id="expando-tab" />'); $('#expando').load('/expando.html'); $("#expando-tab").click(function(){ $("#expando").slideToggle(); }); });
  • 19. Animation is Easy Regular State (overflow: hidden;) Expanded State var baseWidth = $("pre")[0].width(), <pre><code> rightPadding here... ... code in = 10; </code></pre> $("pre").hover(function() { var codeInnerWidth = $("code", this).width() + rightPadding; if (codeInnerWidth > baseWidth) { pre $(this) { overflow: hidden; .stop() width: .css({ 563px; } zIndex: "100", code { position: "relative" font-family: Courier, Monospace; }) } .animate({ width: codeInnerWidth + "px" }); } }, function() { $(this).stop().animate({ width: baseWidth }); });
  • 20. Loading after Loading Big ass movie Starts loading right away, slows down page. $(window).bind(“load”, function() { $('#movie-area').load('/movie.html'); }); Bonus If users don’t have JavaScript, the movie isn’t going to play correctly anyway. So nothing is shown.
  • 21. Controlling Outside Content Design is one thing... Content is another. CSS was able to control the new graphics, but the change in text was done with jQuery.
  • 22. Controlling Outside Content $(function() { $('#coupon-link').text('Enter Voucher Code'); $('#coupon-input').css('display', 'inline'); });
  • 23. MMMmmm Plugins Facebox http://famspam.com/facebox Tablesorter http://tablesorter.com/ Coda Slider http://www.ndoherty.com/demos/coda-slider/1.1.1/ markItUp! http://markitup.jaysalvat.com/home/ jQuery UI http://jqueryui.com/ Interactions Widgets Effects • Draggable • Accordion • Show/Hide Methods • Droppable • Datepicker • Toggle Class • Resizable • Dialog • Color Animation • Selectable • Progressbar • Sortable • Slider • Tabs
  • 24. The FUTURE jQuery CSS Dec. 17 1996 - CSS 1 May 12 1998 - CSS 2 Jan. 14 2006 – jQuery Announced Aug. 26 2006 - jQuery 1.0 Jan. 14 2007 - jQuery 1.1 Jul. 19 2007 - CSS 2.1 Sep. 10 2007 - jQuery 1.2 May 24 2008 - jQuery 1.2.6 Feb. 20 2009 - jQuery 1.3.2 Apr. 23 2009 - CSS 2.1 ??? - CSS 3 Released Usable Recommendations Versions
  • 25. The FUTURE • Huge community of people USING it. • Huge community of DEVELOPERS. • Loads of DOCUMENTATION. • Plenty of SUPPORT available. • Gosh darn it, people like it!