We recommend 10 Great jQuery special effects codes and jquery special effects codes.

Source: Internet
Author: User

We recommend 10 Great jQuery special effects codes and jquery special effects codes.

1. image pre-loading

(function($) { var cache = []; // Arguments are image paths relative to the current page. $.preLoadImages = function() {  var args_len = arguments.length;  for (var i = args_len; i--;) {   var cacheImage = document.createElement('img');   cacheImage.src = arguments[i];   cache.push(cacheImage);  } } jQuery.preLoadImages("image1.gif", "/path/to/image2.png");

2. Open the link in a new window (target = "blank ")

$('a[@rel$='external']').click(function(){   this.target = "_blank";}); /*  Usage:  <a href="http://www.catswhocode.com" rel="external">catswhocode.com</a>*/

3. Add class to the body when JavaScript is supported

/* This code has only one line, but it is the simplest method used to check whether the browser supports JavaScript. if JavaScript is supported, add a hasJS class to the body element */

$('body').addClass('hasJS');

4. Smoothly scroll the page to an anchor.

$(document).ready(function() {  $("a.topLink").click(function() {    $("html, body").animate({      scrollTop: $($(this).attr("href")).offset().top + "px"    }, {      duration: 500,      easing: "swing"    });    return false;  });});

5. Fade-in and fade-out when the mouse slides

$(document).ready(function(){  $(".thumbs img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads   $(".thumbs img").hover(function(){    $(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover  },function(){    $(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout  });});

6. Create a column with a height

var max_height = 0;$("div.col").each(function(){  if ($(this).height() > max_height) { max_height = $(this).height(); }});$("div.col").height(max_height);

7. Enable HTML5 support in some old browsers

(function(){  if(!/*@cc_on!@*/0)    return;  var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})() 

// Then introduce the js in the head
<! -- [If lt IE 9]>
<Script src = "http://html5shim.googlecode.com/svn/trunk/html5.js"> </script>
<! [Endif] -->
8. test whether the browser supports certain CSS3 attributes.

var supports = (function() {  var div = document.createElement('div'),   vendors = 'Khtml Ms O Moz Webkit'.split(' '),   len = vendors.length;   return function(prop) {   if ( prop in div.style ) return true;    prop = prop.replace(/^[a-z]/, function(val) {     return val.toUpperCase();   });    while(len--) {     if ( vendors[len] + prop in div.style ) {      // browser supports box-shadow. Do what you need.      // Or use a bang (!) to test if the browser doesn't.      return true;     }   }   return false;  };})(); if ( supports('textShadow') ) {  document.documentElement.className += ' textShadow';

9. Get the parameters passed in the URL

$.urlParam = function(name){  var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);  if (!results) { return 0; }  return results[1] || 0;}

10. Disable the form's enter key submission

$("#form").keypress(function(e) { if (e.which == 13) {  return false; }});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.