jquery Learning (2)

Source: Internet
Author: User


To automatically scroll through the picture list, click the left and right navigation picture to move, and click the image to enlarge the function:

Many code details are associated with HTML, CSS, but


$ (document). Ready (function () {/* * This function would make the carousel scroll auto-matically. * It's no different than  The Scrollright click Function * Aside from missing a binding to a click function.    The */function Autocarousel () {//outerwidth (True) method returns the width of the element (including padding, borders, and margins), and the 160px,itemwidth of the Li width setting returns 170px; var itemwidth = $ (' #carouselUL Li '). Outerwidth () + 10;//left set -340px;        The returned movefactor is -510px;        var movefactor = parseint ($ (' #carouselUL '). CSS (' left '))-itemwidth; /* Animate the Carousel *//*$ (selector). Animate ({params},speed,callback); -The required params parameter defines the CSS property that forms the animation, and the optional speed parameter specifies the length of the effect; */$ (' #carouselUL '). Animate ({' Left ': movefactor}, ' SL ow ', ' linear ', function () {/* Put the first item after the last item *///:first,:last is a jquery selector;//                To the rear of the last Li;                $ ("#carouselUL li:last"). After ($ ("#carouselUL Li:first")); /* Reset Left Position */$ (' #carouselUL '). css ({' Left ': ' -340px ')});    });    }; /* Make the Carousel scroll automatically when the page loads */var Movecarousel = SetInterval (Autocarousel, 2000);/*    Set original thumbnail opacity */$ ('. Carthumb, #scrollLeft, #scrollRight '). css ({opacity:0.5}); /* Set up a hover function to animate the opacity and stop the Auto-scroll*///hover (defines two functions, separated by ","), and is not mouse related function $ ( '. Carthumb, #scrollLeft, #scrollRight '). The hover (function () {//stop (Stopall,gotoend) method is used to stop animations or effects before they are finished (this). Stop ( ). Animate ({opacity:1}, 75); End Mousein Clearinterval (Movecarousel);  Pause the auto-scroll on mouse over}, function () {$ (this). Stop (). Animate ({opacity:0.5}, 250); End Mouseout Movecarousel = SetInterval (Autocarousel, 2000);        Resume scroll on Mouse out}); /* Click funtion for right scroll */$ (' #scrollRight '). Click (function () {/* Calculate how far to move the carous El */var itemwidth = $ (' #carouselUL Li '). Outerwidth () + 10;        var movefactor = parseint ($ (' #carouselUL '). CSS (' left '))-itemwidth; /* Animate the Carousel */$ (' #carouselUL '). Animate ({' Left ': movefactor}, ' slow ', ' linear ', function ()  {/* Put the first item after the last item */$ ("#carouselUL li:last"). After ($ ("#carouselUL                Li:first "));        /* Reset Left Position */$ (' #carouselUL '). css ({' Left ': ' -340px '});    });    }); /* Click for left scroll */$ (' #scrollLeft '). Click (function () {/* Calculate movement to the left */var ITEMW        Idth = $ (' #carouselUL Li '). Outerwidth () + 10;        var movefactor = parseint ($ (' #carouselUL '). CSS (' left ')) + itemwidth; /* Animate the Carousel */$ (' #carouselUL '). Animate ({' Left ': movefactor}, ' slow ', ' linear ', function () {/* Put the last item before the first *//*before,after, insert the content before and after the selected element; This is equivalent to modifying the DOM structure; */$ (" #caRouselul Li:first "). Before ($ (" #carouselUL li:last "));            /* Reset the Left position */$ (' #carouselUL '). css ({' Left ': ' -340px '});        });        });  /* Click function to load larger pictures */$ ('. Carthumb '). Click (function () {/* Get the source from our image        Tag */var Photoinfo = $ (this). attr ("src");        /* Split the source by the '/' */var Photopatharr = photoinfo.split ('/');        /* The path is the first portion of the array plus a forward slash */var Photopath = photopatharr[0]+ '/';        /* Get an array with the photo name in it */var Photoinfoarr = Photoinfo.split ('_'); /* Now put it back together for using in the photo container */var Photoimgtag = ' <a href=" # "class=" Closephoto "></a></div>"); /* Set the height of the the image to the height of the body-200 pixels to allow for margin */var bodyheight = $ (' bod        Y '). Height ();//Set a single CSS property $ (' #currentPhoto '). CSS (' height ', (bodyHeight-200)); /* * Define the margins so, the modal is centered properly on the screens * we add 40px to the height/  Width to accomodate for the padding and border * Width defined by the image */var modalmargintop =        ($ (' # ' + modalid). Height () + 40)/2;        var modalmarginleft = ($ (' # ' + modalid). Width () + 40)/2; /* Apply the margins to the modal Window */$ (' # ' + modalid). css ({' margin-top ':-modalmargintop, ' margin-left ':-modalmargi        Nleft}); /* Fade in the shade */$ (' body '). Append (' <div id= ' carouselshade ' ></div> '); Add the shade layer to bottom of the body $ (' #carouselShade '). CSS (' opacity ', 0.7). FadeIn (); Set the opacity with JQuery to avoid all of the nasty CSS needed for IE return false;    Keep the link from acting naturally});  /* Close the modal and pull down the shade */$ (' A.closephoto, #carouselShade '). Live (' click ', function () {//        Clicking on the close or shade layer var thismodalid = $ (' A.closephoto '). Parent (). Parent (). attr (' id '); $ ('. Photonote, #carouselShade, # ' +thismodalid). FadeOut (function () {//Summary: #id,. class, between objects using "," delimited, or a hierarchical path $ ('. ph  Otonote, A.closephoto, #carouselShade, #currentPhoto '). Remove ();        Remove the shade and the Close button});    return false; });});


jquery Learning (2)

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.