JQUERY/CSS3 Implement image Cascade expansion effects

Source: Internet
Author: User

This is a jquery and CSS3-based image cascade deployment effect, allowing the mouse to slide over the image to trigger these effects. It consists mainly of HTML, CSS, and jquery code.

HTML code:

Make a list of the small images you want to use, and the HTML structure is very simple.

  1. <div id= "Page_wrap" >
  2. <!--Stack 1--
  3. <div class= "Image_stack" style= "margin-left:600px" >
  4. </div>
  5. <!--Stack 2--
  6. <div class= "Image_stack" style= "margin-left:300px" >
  7. </div>
  8. <div class= "Single_photo" >
  9. <ul id= "Pics" >
  10. <li><a href= "#pic1" title= "Photo" ></a> </li>
  11. </ul>
  12. </div>
  13. </div>

The next step is CSS, which is a bit more complicated because it is useful for some of the CSS3 related features.


CSS code:

Mainly is rotate realizes the picture flips the folding effect, in addition specifies the 0.2s ease animation.

  1. . image_stack img {/* CSS style for photo stack */
  2. Border:none;
  3. Text-decoration:none;
  4. Position:absolute;
  5. margin-left:0px;
  6. width:5074px;
  7. height:5074px;
  8. }
  9. . image_stack {/* CSS style for photo stack */
  10. width:400px;
  11. Position:absolute;
  12. margin:60px 10px 10px;
  13. }
  14. . image_stack img {/* CSS style for photo stack */
  15. Position:absolute;
  16. BORDER:4PX solid #FFF;
  17. box-shadow:2px 2px 8px rgba (0, 0, 0, 0.5);
  18. -moz-box-shadow:2px 2px 8px rgba (0, 0, 0, 0.5);
  19. -webkit-box-shadow:2px 2px 8px rgba (0, 0, 0, 0.5);
  20. z-index:9999;
  21. /* Firefox */
  22. -moz-transition:all 0.2s Ease;
  23. /* WebKit */
  24. -webkit-transition:all 0.2s Ease;
  25. /* Opera */
  26. -o-transition:all 0.2s Ease;
  27. /* Standard */
  28. Transition:all 0.2s Ease;
  29. }
  30. . image_stack #photo1 {/* position of last photo in the stack */
  31. top:8px;
  32. left:108px;
  33. }
  34. . image_stack #photo2 {/* position of Middle photo in the stack */
  35. top:6px;
  36. left:104px;
  37. }
  38. . image_stack #photo3 {/* position of first photo at the top of the stack */
  39. top:4px;
  40. left:100px;
  41. right:100px;
  42. }
  43. . image_stack. rotate1 {/* rotate last image from degrees to the right */
  44. -webkit-transform:rotate (15DEG); /* Safari and Chrome */
  45. -moz-transform:rotate (15deg);/*firefox Browsers * *
  46. Transform:rotate (15deg);/*other */
  47. -ms-transform:rotate (15DEG); /* Internet Explorer 9 */
  48. -o-transform:rotate (15DEG); /* Opera */
  49. }
  50. . image_stack. Rotate2 {/* CSS not used*/
  51. -webkit-transform:rotate (0DEG); /* Safari and Chrome */
  52. -moz-transform:rotate (0deg);/*firefox Browsers * *
  53. Transform:rotate (0deg);/*other */
  54. -ms-transform:rotate (0DEG); /* Internet Explorer 9 */
  55. -o-transform:rotate (0DEG); /* Opera */
  56. }
  57. . image_stack. rotate3 {/*rotate First image degrees to the left*/
  58. -webkit-transform:rotate ( -15DEG); /* Safari and Chrome */
  59. -moz-transform:rotate ( -15DEG); /*firefox Browsers */
  60. Transform:rotate ( -15deg);/*other * *
  61. -ms-transform:rotate ( -15DEG); /* Internet Explorer 9 */
  62. -o-transform:rotate ( -15DEG); /* Opera */
  63. Cursor:pointer;
  64. }

jquery Code:

  1. $ (document). Ready (function () {
  2. $ (". Image_stack"). Delegate (' img ', ' MouseEnter ', function () {//when user hover mouse on image with Div Id=stackphotos
  3. if ($ (this). Hasclass (' Stackphotos ')) {//
  4. The class Stackphotos isn't really defined in CSS, it's only assigned to each images in the photo stack to trigger t He mouseover effect on these photos only
  5. var $parent = $ (this). parent ();
  6. $parent. Find (' img#photo1 '). addclass (' rotate1 ');//add class rotate1,rotate2,rotate3 to each image so, it rotates to th E correct degree in the correct direction (all degrees one to the left, one to the right!)
  7. $parent. Find (' Img#photo2 '). addclass (' Rotate2 ');
  8. $parent. Find (' Img#photo3 '). addclass (' Rotate3 ');
  9. $parent. Find (' img#photo1 '). CSS ("left", "150px"); Reposition the first and last image
  10. $parent. Find (' Img#photo3 '). CSS ("left", "50px");
  11. }
  12. })
  13. . Delegate (' img ', ' MouseLeave ', function () {//When user removes cursor from the image stack
  14. $ (' img#photo1 '). Removeclass (' rotate1 ');//Remove the CSS class that is previously added to make it to its original Positi On
  15. $ (' Img#photo2 '). Removeclass (' Rotate2 ');
  16. $ (' Img#photo3 '). Removeclass (' Rotate3 ');
  17. $ (' img#photo1 '). CSS ("left", "");//Remove the CSS property ' left ' value from the DOM
  18. $ (' Img#photo3 '). CSS ("left", "");
  19. });;
  20. });

In fact, jquery is nothing, mainly dynamic for the picture to add and delete classes, with addclass and removeclass implementation, so that the mouse can be flipped over the picture to flip, the mouse away from the image can be restored, very good.

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.