Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- var offset = 0
- var limit = 50
- var city = ""
- $("#base").show()
- $("#detailed").hide()
- $("li").click(function () {
- city = $(this).html()
- console.log(city)
- $("#base").html("")
- offset = 0
- processData(city)
- })
- function processData(city) {
- $.ajax({
- url: "https://partner-api.groupon.com/deals.json?tsToken=US_AFF_0_987654_123456_0&division_id=" + city + "&offset=" + offset + "&limit=" + limit,
- dataType: "jsonp",
- success: function (data) {
- $.each(data.deals, function(i, item){
- var img = $("<img/>")
- img.attr("width", "200px")
- img.attr("height", "150px")
- img.attr("title", item.title)
- img.attr("date-from", item.startAt)
- img.attr("date-to", item.endAt)
- img.attr("src", item.largeImageUrl)
- img.appendTo("#base")
- })
- }
- })
- offset+=limit
- }
- $(document).on("click", "#base img", function () {
- $("#title").html($(this).attr("title"))
- $("#from").html($(this).attr("date-from"))
- $("#to").html($(this).attr("date-to"))
- $("#image_detailed").attr("src",$(this).attr("src"))
- $("#base").hide()
- $("#detailed").show()
- console.log($(this).attr("title"))
- })
- $("#back").click(function () {
- $("#base").show()
- $("#detailed").hide()
- })
- $(window).scroll(function () {
- if($(window).scrollTop() >= $(document).height()-$(window).height()-100){
- processData(city)
- }
- })
- })
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <link rel="stylesheet" href="jquery/jquery-ui.css">
- <script src="jquery/jquery.js"></script>
- <script src="jquery/jquery-ui.js"></script>
- <script src="script.js"></script>
- <style>
- </style>
- </head>
- <body>
- <ul>
- <li>Chicago</li>
- <li>Seattle</li>
- <li>Orlando</li>
- </ul>
- <div id="base">
- </div>
- <div id="detailed">
- <p id="title"></p>
- <p id="from"></p>
- <p id="to"></p>
- <img id="image_detailed">
- <button id="back">Back</button>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement