讯睿CMS内容页自定义评论列表调用

      发布在:后端技术      评论:0 条评论

有的时候我们需要实现打开内容页直接定位到某天留言位置,所以就需要用的锚点的。

原来模版的写法

<!--调用ajax评论-->
{if IS_COMMENT}
{dr_module_comment(MOD_DIR, $id)}
{/if}

在此就需要对dr_module_comment评论函数进行自定义

 <!--调用ajax评论自定义模版调用方式-->
   {if IS_COMMENT}
   <div id="dr_module_comment_{$id}"></div>
<script type="text/javascript">
function dr_ajax_module_comment_{$id}(type, page) {
var index = layer.load(2, { time: 10000 });
$.ajax({type: "GET", url: "/index.php?s={MOD_DIR}&c=comment&m=index&id={$id}&type="+type+"&page="+page+"&"+Math.random(), dataType:"jsonp",
success: function (data) {
layer.close(index);
if (data.code) {
$("#dr_module_comment_{$id}").html(data.msg);
//自定义新增滚动到指定评论位置
                   if($(location.hash).length>0){
console.log('$(location.hash).offset().top=',$(location.hash).offset().top);
$(window).scrollTop(parseInt($(location.hash).offset().top)-100);
}
} else {
dr_tips(0, data.msg);
}
},
error: function(HttpRequest, ajaxOptions, thrownError) {
layer.closeAll();
alert("评论调用函数返回错误:"+HttpRequest.responseText);
}
});
}
dr_ajax_module_comment_{$id}(0, 1);
</script>
{/if}


热门推荐