Advertisement
LegoDrifter

Shabloni Something

Dec 23rd, 2020
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. $(document).ready(function () {
  2. var offset = 0
  3. var limit = 50
  4. var city = ""
  5. $("#base").show()
  6. $("#detailed").hide()
  7. $("li").click(function () {
  8. city = $(this).html()
  9. console.log(city)
  10. $("#base").html("")
  11. offset = 0
  12. processData(city)
  13. })
  14.  
  15. function processData(city) {
  16. $.ajax({
  17. url: "https://partner-api.groupon.com/deals.json?tsToken=US_AFF_0_987654_123456_0&division_id=" + city + "&offset=" + offset + "&limit=" + limit,
  18. dataType: "jsonp",
  19. success: function (data) {
  20. $.each(data.deals, function(i, item){
  21. var img = $("<img/>")
  22. img.attr("width", "200px")
  23. img.attr("height", "150px")
  24. img.attr("title", item.title)
  25. img.attr("date-from", item.startAt)
  26. img.attr("date-to", item.endAt)
  27. img.attr("src", item.largeImageUrl)
  28. img.appendTo("#base")
  29.  
  30. })
  31. }
  32. })
  33. offset+=limit
  34. }
  35.  
  36. $(document).on("click", "#base img", function () {
  37. $("#title").html($(this).attr("title"))
  38. $("#from").html($(this).attr("date-from"))
  39. $("#to").html($(this).attr("date-to"))
  40. $("#image_detailed").attr("src",$(this).attr("src"))
  41. $("#base").hide()
  42. $("#detailed").show()
  43. console.log($(this).attr("title"))
  44. })
  45.  
  46. $("#back").click(function () {
  47. $("#base").show()
  48. $("#detailed").hide()
  49. })
  50.  
  51. $(window).scroll(function () {
  52. if($(window).scrollTop() >= $(document).height()-$(window).height()-100){
  53. processData(city)
  54. }
  55. })
  56.  
  57. })
  58.  
  59.  
  60. <!DOCTYPE html>
  61. <html>
  62. <head>
  63. <meta charset="UTF-8">
  64. <title>Title</title>
  65. <link rel="stylesheet" href="jquery/jquery-ui.css">
  66. <script src="jquery/jquery.js"></script>
  67. <script src="jquery/jquery-ui.js"></script>
  68. <script src="script.js"></script>
  69. <style>
  70. </style>
  71. </head>
  72. <body>
  73. <ul>
  74. <li>Chicago</li>
  75. <li>Seattle</li>
  76. <li>Orlando</li>
  77. </ul>
  78.  
  79. <div id="base">
  80.  
  81. </div>
  82.  
  83. <div id="detailed">
  84. <p id="title"></p>
  85. <p id="from"></p>
  86. <p id="to"></p>
  87. <img id="image_detailed">
  88. <button id="back">Back</button>
  89. </div>
  90.  
  91. </body>
  92. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement