几秒钟后向下滚动到锚点 [英] Scrolling down after a few seconds to an anchor

查看:115
本文介绍了几秒钟后向下滚动到锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能在6秒后向下滚动到锚点?

我发现此脚本在其中向下滚动了几个像素,但这并不是我想要的.

 < script type ='text/javascript'>setTimeout("window.scrollBy(0,270);",6000);</script> 

我又如何使其向下平滑滚动?我找到了,但是如何将其与其他脚本结合在一起?

  function scrollToAnchor(aid){var aTag = $("a [name ='" + aid +']");$('html,body').animate({scrollTop:aTag.offset().top},'slow');}$(#link").click(function(){scrollToAnchor('id3');}); 

我对JS不太熟悉,所以非常感谢您的帮助:)

我正在工作的网站是: kip.mascomm.be

更新:

感谢Seth,我得到了第一部分的工作,但是有人可以给我代码使性能平稳吗?

  var delay = 1000 * 10;setTimeout(function(){location.hash ="#kippenkramen";}, 延迟); 

解决方案

时间延迟示例:

  var delay = 1000 * 6;//1 * 6秒setTimeout(function(){//window.scrollTo(500,0);//滚动到特定位置//location.hash ="#elmentid";//滚动到具有给定id的元素},延迟); 

(如何在javascript中设置时间延迟)

动画滚动功能:

 功能scrollTo(element,to,duration){如果(持续时间< 0)返回;var差异=到-element.scrollTop;var perTick =差异/持续时间* 10;setTimeout(function(){element.scrollTop = element.scrollTop + perTick;如果(element.scrollTop == to)返回;scrollTo(element,to,duration-10);},10);} 

(跨浏览器JavaScript(不是jQuery ...)滚动到顶部动画)

I wonder if it's possible to scroll down after 6 seconds to an anchor?

I found this script where it scrolls down a couple of pixels but it's not completely what I'm looking for.

<script type='text/javascript'>
     setTimeout("window.scrollBy(0,270);",6000);
</script>

Also how can i make it scroll down smoothly? I found this but how do i combine it with the other script?

function scrollToAnchor(aid) {
     var aTag = $("a[name='" + aid + "']");
     $('html,body').animate({scrollTop: aTag.offset().top},'slow');
}

$("#link").click(function() {
     scrollToAnchor('id3');
});

I'm not very familiar with JS so I would really appreciate some help :)

the site I'm working is: kip.mascomm.be

UPDATE:

I got the first part to work, thanks to Seth, but can someone please give me a code to make the performance smooth:

var delay = 1000 * 10;
    setTimeout(function() {
        location.hash = "#kippenkramen";
    }, delay);

解决方案

Time Delay example:

var delay=1000 * 6;//1*6 seconds
setTimeout(function(){
  //window.scrollTo(500, 0);//scrolls to specific location
  //location.hash = "#elmentid"; //scrolls to element with given id
},delay); 

(How to set time delay in javascript)

Animated Scrolling function:

function scrollTo(element, to, duration) {
  if (duration < 0) return;
  var difference = to - element.scrollTop;
  var perTick = difference / duration * 10;

  setTimeout(function() {
    element.scrollTop = element.scrollTop + perTick;
    if (element.scrollTop == to) return;
    scrollTo(element, to, duration - 10);
  }, 10);
}

(Cross browser JavaScript (not jQuery...) scroll to top animation)

这篇关于几秒钟后向下滚动到锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆