Advertisement
asimryu

main.js

Jan 18th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.42 KB | None | 0 0
  1. // main.js
  2.  
  3. $(".topic img").on("click",function(e){
  4.     $("#popup").hide();
  5.     // 화면 한가운데 위치 조정
  6.     // var wh = $(window).height() / 2;
  7.     // var ww = $(window).width() / 2;
  8.     // var x = ww - 250;
  9.     // var y = wh - 250;
  10.     // 마우스 포인터 위치
  11.     var x = e.pageX - 250;
  12.     var y = e.pageY - 250;
  13.     $("#popup").css({left:x+"px",top:y+"px"});
  14.     var src = $(this).attr("src");
  15.     var img = "<img src='" + src + "' width='500' height='500'>";
  16.     $("#popup").html(img);
  17.     $("#popup").show("slow");
  18. });
  19.  
  20. $("#popup").on("click",function(){
  21.     $(this).hide("slow");
  22. });
  23.  
  24. var page=1;
  25.  
  26. function getPage(){
  27.     $.getJSON("list.php?page="+page,function(d){
  28.         if( ! d ) return; // ! = not/false
  29.         for( i=0; i<d.length; i++) {
  30.             var title = d[i].title;
  31.             var writer = d[i].writer;
  32.             var wdate = d[i].wdate;
  33.             var tr = "<tr data-id='" + d[i].id + "'>";
  34.             tr += "<td>" + title + "</td>";
  35.             tr += "<td>" + writer + "</td>";
  36.             tr += "<td>" + wdate.substring(0,10) + "</td>";
  37.             tr += "<td><button class='del btn btn-danger btn-xs'><span class='glyphicon glyphicon-trash'></span>삭제</button> <button class='edit btn btn-info btn-xs'><span class='glyphicon glyphicon-pencil'></span>수정</button></td>";
  38.             tr += "</tr>";
  39.             $("#board tr:last").after(tr);
  40.         }
  41.     });
  42. }
  43.  
  44. getPage();
  45.  
  46.  
  47. $("#board").on("click",".del",function(){
  48.     var id = $(this).parent("td").parent("tr").attr("data-id");
  49.     //alert(id);
  50.     var del = confirm("정말 지울까요?");
  51.     if( ! del ) return;
  52.     $.post("delete.php",{"id":id},function(){
  53.         location.reload();
  54.     });
  55. });
  56.  
  57. $("#board").on("click",".edit",function(){
  58.     var id = $(this).parent("td").parent("tr").attr("data-id");
  59.     location.href = "write.php?id=" + id;
  60. });
  61.  
  62. // var app = angular.module("myApp",[]);
  63. // app.controller("myBoard",function($scope,$http){
  64. //  $http.get("board.json").then(function(d){
  65. //      $scope.board = d.data;
  66. //  });
  67. // });
  68.  
  69.  
  70. $(window).scroll(function(){
  71.     var scrollHeight = $(document).height();
  72.     var windowHeight = $(window).height();
  73.     var scrollTop = $(window).scrollTop();
  74.     var scrollButtom = windowHeight + scrollTop;
  75.     console.log("scrollHeight=" + scrollHeight);
  76.     console.log("windowHeight=" + windowHeight);
  77.     console.log("scrollTop=" + scrollTop);
  78.     console.log("scrollButtom=" + scrollButtom);
  79.     console.log("스크롤결과=" + ((scrollHeight-scrollButtom)/scrollHeight));
  80.     if( (scrollHeight-scrollButtom)/scrollHeight === 0 ) {
  81.         page++;
  82.         getPage();
  83.     }
  84. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement