Latkoski

beskonecna lista

Dec 21st, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Responsive Navigation</title>
  5.     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  6.     <style>
  7.         .content{background:#eef; padding: 5px; border:1px gray dotted; font-size: 1.4em; float:left}
  8.     </style>
  9.    
  10.     <link rel="stylesheet" href="style.css">
  11.     <script type="text/javascript" src="jquery-2.1.0.min.js"></script>
  12.     <script>
  13.         var category = "";
  14.         var offset = 0;
  15.         var limit = 50;
  16.         $(function() {
  17.             $("#itemDet").hide();
  18.             var pull = $('#pull');
  19.                 menu = $('nav ul');
  20.                 menuHeight = menu.height();
  21.  
  22.             $(pull).on('click', function(e) {
  23.                 e.preventDefault();
  24.                 menu.slideToggle();
  25.             });
  26.  
  27.             $(window).resize(function(){
  28.                 var w = $(window).width();
  29.                 if(w > 320 && menu.is(':hidden')) {
  30.                     menu.removeAttr('style');
  31.                 }
  32.             });
  33.            
  34.            
  35.             $('li').click(function(e) {
  36.                 category = $(this).find('a').text();
  37.                 offset = 0;
  38.                 getPhotos(category, offset, limit);
  39.             });
  40.            
  41.             $(window).scroll(function(){
  42.                 if  ($(window).scrollTop() >= $(document).height() - $(window).height() - 200){
  43.                     offset+=limit;
  44.                     getPhotos(category, offset, limit);
  45.                 }
  46.             });
  47.             $("body").on("click", "img", function(){           
  48.                 var im = $(this);
  49.                 $('#items').hide();
  50.                 $('#itemDet').show();
  51.                 $('#title').append("<a href='"+im.attr('buyUrl')+"'>" + im.attr('title') + "</a>");
  52.                 $('#from').html(im.attr("date-from"));
  53.                 $('#to').html(im.attr("date-to"));
  54.                 $('#im').append("<img src='" + im.attr("src") + "'><img>");
  55.                 var tmp = im.attr('buyUrl');
  56.                 tmp = tmp.substring(tmp.indexOf("http"));
  57.                 var full="https://www.facebook.com/sharer/sharer.php?u="+tmp;
  58.                 $('#share').append("<a style='color:#ffffff' href = '"+full+"' target='_blank'> Share on Facebook </a>");
  59.             });
  60.             $(".selected").on("click", "img", function(){
  61.                 $('img').removeClass('selected');
  62.                 $(this).addClass('selected');
  63.                
  64.             });
  65.             $('#top').click(function(){
  66.                 $("#itemDet").hide();
  67.                 $("#items").show();
  68.                 $('#title a').remove();
  69.                 $('#from').html("");
  70.                 $('#to').html("");
  71.                 $('#im img').remove();
  72.                 $('#shlare a').remove();
  73.             });
  74.  
  75.            
  76.         });
  77.        
  78.         function getPhotos(category, offset, limit){
  79.             if (offset == 0) $('#items').html("<img src='animate.gif' style='display:block;width:15px;'/>");
  80.             $.ajax({
  81.                 url: "https://partner-api.groupon.com/deals.json?tsToken=US_AFF_0_987654_123456_0&division_id=" + category + "&offset=" + offset + "&limit=" + limit,
  82.                 dataType: "jsonp",
  83.                 success: function (data) {                     
  84.                     if (offset == 0) $('#items').html("");
  85.                     $.each( data.deals, function( i, item ) {
  86.                         var img = $("<img/>");
  87.                         img.attr('width', '200px');
  88.                         img.attr('height', '150px');
  89.                         img.attr('title', item.title);
  90.                         img.attr("date-from", item.startAt);
  91.                         img.attr("date-to", item.endAt);
  92.                         img.attr("buyUrl", item.dealUrl);
  93.                         img.attr("src", item.largeImageUrl).appendTo("#items");
  94.                        
  95.                     });
  96.                 },
  97.                 error: function (e) {
  98.                     alert("Error: " + e.responseText);
  99.                 }              
  100.             });
  101.         }              
  102.     </script>
  103. </head>
  104. <body>
  105.     <nav class="clearfix">
  106.    
  107.         <ul class="clearfix">
  108.             <li><a href="javascript:void(0)">Chicago</a></li>
  109.             <li><a href="javascript:void(0)">Seattle</a></li>
  110.             <li><a href="javascript:void(0)">Orlando</a></li>
  111.             <li><a href="javascript:void(0)">Atlanta</a></li>
  112.             <li><a href="javascript:void(0)">Houston</a></li>
  113.             <li><a href="javascript:void(0)">Miami</a></li>
  114.         </ul>
  115.         <a href="javascript:void(0)" id="pull">Menu</a>
  116.        
  117.     </nav>
  118.    
  119.     <br>
  120.     <br>
  121.     <div style="text-align:center" id='items'></div>
  122.     <div style="text-align:center" id='itemDet'>
  123.         <div id="title" class="content"> </div>
  124.         <label class="content" style="clear:both">Date from:</label>
  125.         <div id="from" class="content"></div>
  126.         <label class="content" style="clear:both">Date to:</label>
  127.         <div id="to" class="content"></div>
  128.         <div id="im" style="float:left;clear: both;padding-top: 20px;"></div>
  129.         <div id="share" style="float:left; background:#0000ff;" ></div>
  130.         <input id="top" style="float:left;clear: both; font-size: 1.4em;" value="Back" type="button"/>
  131.        
  132.     </div>
  133. </body>
  134. </html>
  135. Chat Conversation End
Advertisement
Add Comment
Please, Sign In to add comment