Advertisement
rdsedmundo

slider.html

Sep 10th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.91 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title></title>
  6.  
  7.     <style media="screen">
  8.       .kyl_slider {
  9.         margin: 0 auto;
  10.         position: relative;
  11.         overflow: hidden;
  12.       }
  13.  
  14.       .kyl_slider .first, .kyl_slider .last {
  15.         width: 50%;
  16.       }
  17.  
  18.       .kyl_slider .divisor {
  19.         position: absolute;
  20.           top: -10%;
  21.         z-index: 999;
  22.         width: 42px;
  23.         height: 556px;
  24.         background-image: url(divisor.png);
  25.         background-size: cover;
  26.         background-repeat: no-repeat;
  27.       }
  28.  
  29.       .kyl_slider .information {
  30.         position: absolute;
  31.         bottom: 5%;
  32.         left: 3%;
  33.         background-color:rgba(0, 0, 0, 0.6);
  34.         padding: 10px;
  35.         color: #FFF;
  36.         text-transform: uppercase;
  37.       }
  38.     </style>
  39.  
  40.     <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  41.  
  42.     <script type="text/javascript">
  43. $(function() {
  44.         /**
  45.             @author edmundo-rodrigues@hotmail.com.br
  46.         */
  47.         var configs = {
  48.              "width": "720px",
  49.             "height": "405px"
  50.         }
  51.  
  52.         var slider = $(".kyl_slider").css(configs);
  53.         var divisor_width = 42;
  54.     var default_text  = "passe o mouse para comparar";
  55.  
  56.         slider.each(function () {
  57.             var $$ = $(this);
  58.  
  59.       $$.append("<div class='information'>" + default_text + "</div>");
  60.       $$.append("<div class='divisor'></div>");
  61.  
  62.             var back_css = {
  63.                 "background-size": "auto " + configs.height,
  64.                 "background-repeat": "no-repeat",
  65.           "height": configs.height,
  66.                 "float": "left"
  67.             };
  68.  
  69.             ["first", "last"].forEach(function (the_class) {
  70.                 var the_container = $$.find("." + the_class);
  71.  
  72.                 var the_image     = the_container.removeClass(the_class).find("img");
  73.                 the_image.css("display", "none");
  74.  
  75.                 the_container.addClass(the_class).css(back_css).css("background-image", "url("+ the_image.attr("src") +")");
  76.             });
  77.  
  78.         });
  79.  
  80.     slider.find(".divisor").css("left", slider.width()/2 - divisor_width/2);
  81.  
  82.         slider.mousemove(function (event) {
  83.                 var $$ = $(this);
  84.  
  85.                 var _x = event.pageX - $$.offset().left;
  86.  
  87.         if (_x < $$.width()/2)
  88.          $$.find(".information").html("antes");
  89.        else {
  90.  
  91.            $$.find(".information").html("depois");
  92.        }
  93.  
  94.                 if (_x < 15) {
  95.                     _x = 0;
  96.                     $$.find(".divisor").css("left", -(divisor_width/2) - 2);
  97.                 } else if (_x > $$.width() - 15) {
  98.                     _x = $$.width();
  99.                     $$.find(".divisor").css("left", _x - 20);
  100.                 } else
  101.                     $$.find(".divisor").css("left", _x - 20);
  102.  
  103.                 var _first = $$.find(".first").first();
  104.                 var _last  = $$.find(".last").last();
  105.  
  106.                 _first.width(_x);
  107.                 _last.width($$.width() - _x);
  108.         });
  109. });
  110.     </script>
  111.   </head>
  112.   <body>
  113.  
  114.     <div class="kyl_slider">
  115.         <div class="first">
  116.           <img src="1.jpg" />
  117.         </div>
  118.  
  119.         <div class="last">
  120.           <img src="2.jpg" />
  121.         </div>
  122.     </div>
  123.  
  124.   </body>
  125. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement