common.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. $(function () {
  2. $('.radio label').each(function () {
  3. var e = $(this);
  4. e.click(function () {
  5. e.closest('.radio').find("label").removeClass("active");
  6. e.addClass("active");
  7. });
  8. });
  9. $('.checkbox label').each(function () {
  10. var e = $(this);
  11. e.click(function () {
  12. if (e.find('input').is(':checked')) {
  13. e.addClass("active");
  14. } else {
  15. e.removeClass("active");
  16. }
  17. });
  18. });
  19. $('.icon-navicon').each(function () {
  20. var e = $(this);
  21. var target = e.attr("data-target");
  22. e.click(function () {
  23. $(target).slideToggle().toggleClass("nav-navicon");
  24. });
  25. });
  26. // 加载更多
  27. $(document).on("click", ".btn-loadmore", function () {
  28. var that = this;
  29. var page = parseInt($(this).data("page"));
  30. page++;
  31. $(that).prop("disabled", true);
  32. $.ajax({
  33. url: $(that).attr("href"),
  34. success: function (data, ret) {
  35. $(data).insertBefore($(that).parent());
  36. $(that).remove();
  37. return false;
  38. },
  39. error: function (data) {
  40. }
  41. });
  42. return false;
  43. });
  44. //自动加载更多
  45. $(window).scroll(function () {
  46. var loadmore = $(".btn-loadmore");
  47. if (loadmore.size() > 0 && !loadmore.prop("disabled")) {
  48. if ($(window).scrollTop() - loadmore.height() > loadmore.offset().top - $(window).height()) {
  49. loadmore.trigger("click");
  50. }
  51. }
  52. });
  53. setTimeout(function () {
  54. if ($(window).scrollTop() > 0) {
  55. $(window).trigger("scroll");
  56. }
  57. }, 500);
  58. // 回到顶部
  59. $(document).on('click', ".gotop", function (e) {
  60. e.preventDefault();
  61. $('html,body').animate({
  62. scrollTop: 0
  63. }, 700);
  64. });
  65. });