- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
仍在我的网站上工作:http://i333180.iris.fhict.nl/p2_vc/
有一个向下导航页面的按钮, Action 是即时的,但平滑滚动更好。
所以,我四处搜索,尝试了很多东西,我找到的最短的脚本是这个,但我无法让它工作:
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
引用:https://css-tricks.com/snippets/jquery/smooth-scrolling/
这就是我在代码之间添加的方式:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
</script>
</head>
按钮:
<body>
<a id='button_down' href='#section' onclick="document.getElementById('moodvideo').pause()"><img src='scroll.png' alt='Scroll'></a>
</body>
我检查了给出的示例站点,并以相同的方式将其添加到我的 html 中。引用检查链接:https://css-tricks.com/examples/SmoothPageScroll/但我无法让它工作..
此外,我还有另一个脚本,它需要在视频结束后执行相同的操作。现在的脚本是:
<script>
function videoEnded() {
window.location.href="#section";
}
</script>
这必须做同样的事情;很好地滚动。
我希望我解释的很清楚,如果不是,我想再试一次。问候
编辑 脚本未添加到在线站点,因为该脚本尚未运行,如果这样更容易,我可以在线添加它。
更新 站点在线但脚本不工作...
最佳答案
该脚本按预期作用于您的 Live Copy 上的链接,所以我相信您指的是您的 videoEnd()
功能。
您找到的平滑滚动脚本仅适用于 anchor 标记 (<a>
)。
作为window.location.href = "#section"
不是 anchor 标签,不受脚本影响。
然而,您可以做的是获取该脚本的重要部分并将其用于您的 videoEnd()
像这样的功能。
function videoEnded() {
$('html,body').animate({
scrollTop: $("#section").offset().top
}, 1000);
}
编辑:
它对您不起作用的原因是您正在使用 file://
浏览页面协议(protocol)和链接到 jQuery 的脚本源是
//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
它使用 //
relative scheme,意思是浏览器会追加当前的浏览scheme,变成这个..
file://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
这是不存在的。如果指定 http://
它会起作用
http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
关于Javascript smoothscroll 由于某种原因不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30831454/
我正在处理我的新作品集,但我遇到了一个没有帮助无法解决的问题。到目前为止,这里有我网站的链接:www.jsfiddle.net/Cessum/pmaefrjo/ 我想要的是,当您点击 creaties
我一直在尝试让我的 anchor 平滑滚动,但它不起作用。我一直使用脚本 Smoothscroll.js,但这在该网站上无法正常工作?我尝试过使用许多其他脚本来使操作起作用,但没有任何效果。关于让 S
仍在我的网站上工作:http://i333180.iris.fhict.nl/p2_vc/ 有一个向下导航页面的按钮, Action 是即时的,但平滑滚动更好。 所以,我四处搜索,尝试了很多东西,我找
有人可以帮助我吗?尝试通过我的平滑滚动和控制速度添加“慢”功能。 希望能够实现真正的“平滑滚动”。 代码如下: $(document).ready(function(){ $('.smoothscro
我有以下 Github 示例:A sample to showcase contact list divided into sections with group header 在 Adapter 类
我有以下布局: 在我的 recyclerview 适配器中: @Override public void onBind
当我滚动到它时,我试图将列表 元素的类更改为 class="active"。 function onScroll(event){ var scrollPos = $(document).scrollT
我正在使用以下脚本在单页网站上启用平滑滚动。 对于导航,我使用固定的导航栏,它位于页面顶部的最上层 z-index 层。栏的高度是 108 像素,所以当我使用 smoothscroller 时,我想导
我有一种情况,我正在使用带有图像的水平 ScrollView 并使用按钮平滑滚动到不同的图像位置。现在它工作正常我只是想知道是否有人知道减慢平滑滚动方法,即有更长的动画时间?目前,捕捉发生得非常快。
是否有一种简单的方法可以以最小屏幕宽度初始化 Fx.SmoothScroll,并在下面禁用它? 例如,我只希望平滑滚动发生在 400 像素以上。 为什么,因为显示/隐藏响应式菜单会干扰滚动目标位置,所
来自 Lim Chee Un 在这里发表的帖子: http://davidwalsh.name/mootools-onload-smoothscroll window.addEvent(‘domrea
我有一个位于窗口顶部的 div,我将其设为 position:fixed,因此当我向下滚动时,它会粘在窗口上。我有一个名为 post 的按钮。如果我单击该按钮,它将调用方法激活。每当我单击该按钮时,我
我创建了一个自定义 ScrollView ,并向其中动态添加了一些 ImageView 。我只想在初始化 View 时将 ScrollView 滚动到特定位置。我使用 scrollview.smoot
这个函数在我的另一个页面上运行良好,但是当我从另一个页面调用相同的函数时,它会给出错误(TypeError:jQuery.smoothScroll 不是函数 jQuery.smoothScroll({
我已经使用 bootstrap 4 有一段时间了。看到了为什么 smoothscroll 应该起作用的多次解释,但我仍然没有找到它! 也许有人可以解释为什么它对我不起作用?或者我的编码有什么问题? 伟
我正在使用对 smoothscroll.init() 的调用,如下所示: new WOW().init(); //smoothScroll smoothScroll.init(); 但我收到以下错误:
这个问题在这里已经有了答案: Change ViewPager animation duration when sliding programmatically (7 个答案) 关闭 8 年前。 我
jQuery localScroll 和 smoothScroll 在我的网站上根本不起作用。我的控制台中出现错误,指出我的函数未定义并且这是类型错误。 关于如何解决此问题并使插件正常工作有什么建议吗
我有一个向下按钮 div,我想添加 smoothScroll 类,这样当单击它时,平滑滚动会在它跳转到 JS 文件中附加到它的链接之前发生。我只是不确定如何让 addClass 在 window.lo
当我使用 smoothscroll 插件定位 name 属性时,平滑滚动不起作用,但如果我定位 id 属性,smoothscroll 工作正常。出现以下控制台错误,请建议如何解决。 $(documen
我是一名优秀的程序员,十分优秀!