我在使用 jquery 方面还很陌生,但每天都在学习一点。我已经解决了很多搜索这个网站的问题,但我似乎找不到解决这个问题的方法:
我目前工作的网站使用了很多页面 anchor 。
我有 localscroll 和 scrollto 作为 jquery 库。
我用这个小脚本为过渡动画:
<script type="text/javascript">
$(document).ready(function () {
$('.scrolllento').localScroll({ duration: 1000 });
});
</script>
无论我将“scrolllento”类添加到我的链接的容器中,它都能正常工作。
现在我遇到的问题是当链接跳转到不同页面内部的 anchor 时。我的客户问我是否可以先加载页面然后移动到具有相同网络转换的 anchor 。
我一直在用我的小知识研究它,这就是我所拥有的 atm:
<script type="text/javascript">
$(document).ready(function () {
var nosalto = $(location).attr('href');
if (nosalto.indexOf("HistoriaBMG") > 0) {
$.fn.gotoAnchor = function (anchor) {
location.href = this.selector;
}
$('#historia').gotoAnchor();
}
});
</script>
“HistoriaBMG”是新页面,“#historia”是我想进入该页面的 anchor 。
而且它似乎再次起作用了......
问题是我现在不知道如何实现转换,因为链接容器中的类“scrolllento”被忽略了../HistoriaBMG。
谁能帮帮我?非常感谢,请原谅我的英语,希望这个问题足够清楚。
最佳答案
根据localScroll docs :
The plugin also adds a function, $.localScroll.hash() , that checks the URL in the address bar, and if there's a hash(#an_id), it will scroll to the element. It accepts a hash of settings, just like $.localScroll. You will likely call it on document ready. Check the regular example to see it in action.
所以你只需要调用$.localScroll.hash()
在 $(document).ready()
关于javascript - 加载添加转换后转到页面 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21849186/