te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to set scroll to top on refreshload? (AngularJs or Js only, no Jquery) - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set scroll to top on refreshload? (AngularJs or Js only, no Jquery) - Stack Overflow

programmeradmin4浏览0评论

Here is my problem, I am searching to set the scroll to top of the page on load but currently Chrome, IE and Firefox reset the scroll position to the same as it was on previous page, so how can I set scroll to top?

It seems that scrollTo is just ignored by those web browsers and I tried many over methods using scrollTo (find on SO) but they all do nothing...

Need help! Thank you all!

Here is my problem, I am searching to set the scroll to top of the page on load but currently Chrome, IE and Firefox reset the scroll position to the same as it was on previous page, so how can I set scroll to top?

It seems that scrollTo is just ignored by those web browsers and I tried many over methods using scrollTo (find on SO) but they all do nothing...

Need help! Thank you all!

Share Improve this question edited Sep 8, 2016 at 12:11 Mukesh Ram 6,3284 gold badges20 silver badges37 bronze badges asked Sep 8, 2016 at 9:22 N.KN.K 1,6902 gold badges22 silver badges32 bronze badges 2
  • Browser automatically sets the scroller to the top. Some code must be changing it. – Flying Gambit Commented Sep 8, 2016 at 9:28
  • I'am sure thats not the case, many people have the same problem and it has been reported as a convenience feature of chrome for exemple he rememeber the last scroll position and automatically set it back on reload/load :3 edit: Thank you anyay :) – N.K Commented Sep 8, 2016 at 9:34
Add a ment  | 

4 Answers 4

Reset to default 11

Okay, in case it can help some of you guys, here is what i'am using right now (i just found it, like 30 seconds after posting the question lmao...) and it seems to work:

window.onbeforeunload = function() {window.scrollTo(0,0);}

Edit: it might be because the browser remembers the last scroll pos, so setting it to top before unload makes, for exemple, chrome remembering 0,0 instead of x,y

You could try somthing like this :

<!DOCTYPE html>
<html>
<body onload="myFunction()">

<script>
function myFunction() {
    document.body.scrollTop = document.documentElement.scrollTop = 0;
}
</script>

</body>
</html>

Hope it helps :)

This is our vanilla javascript implementation. It has a simple easing effect so that the user doesn't get shocked after clicking the To Top button.

Its very small and gets even smaller when minified. Devs looking for an alternative to the jquery method but want the same results can try this.

HTML

<button id="to-top">To Top</button>

JS

document.querySelector("#to-top").addEventListener("click", function(){

var toTopInterval = setInterval(function(){

    var supportedScrollTop = document.body.scrollTop > 0 ? document.body : document.documentElement;

    if (supportedScrollTop.scrollTop > 0) {
        supportedScrollTop.scrollTop = supportedScrollTop.scrollTop - 50;
    }

    if (supportedScrollTop.scrollTop < 1) {
        clearInterval(toTopInterval);
    }

}, 10);

 },false);

you can use $anchorScroll()

and here is a documentation for it angular-js: anchor-Scroll attribute

发布评论

评论列表(0)

  1. 暂无评论