layui.use(['jquery', 'helper'], function () { var $ = layui.jquery; var helper = layui.helper; var $related = $('#related-article-list'); helper.ajaxLoadHtml($related.data('url'), $related.attr('id')); $('.icon-star').on('click', function () { var $this = $(this); var $parent = $this.parent(); var $favoriteCount = $parent.next(); var favoriteCount = parseInt($favoriteCount.text()) helper.checkLogin(function () { $.ajax({ type: 'POST', url: $parent.data('url'), success: function () { if ($this.hasClass('layui-icon-star-fill')) { $this.removeClass('layui-icon-star-fill'); $this.addClass('layui-icon-star'); $parent.attr('title', '收藏'); $favoriteCount.text(favoriteCount - 1); favoriteCount -= 1; } else { $this.removeClass('layui-icon-star'); $this.addClass('layui-icon-star-fill'); $parent.attr('title', '取消收藏'); $favoriteCount.text(favoriteCount + 1); favoriteCount += 1; } } }); }); }); $('.icon-praise').on('click', function () { var $this = $(this); var $parent = $this.parent(); var $likeCount = $parent.next(); var likeCount = parseInt($likeCount.text()); helper.checkLogin(function () { $.ajax({ type: 'POST', url: $parent.data('url'), success: function () { if ($this.hasClass('active')) { $this.removeClass('active'); $parent.attr('title', '点赞'); $likeCount.text(likeCount - 1); likeCount -= 1; } else { $this.addClass('active'); $parent.attr('title', '取消点赞'); $likeCount.text(likeCount + 1); likeCount += 1; } } }); }); }); $('.icon-reply').on('click', function () { console.log('scroll'); console.log($('#comment-wrap').offset().top); $('html').animate({ scrollTop: $('#comment-wrap').offset().top }, 500); }); });