作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的主页底部,我添加了一个联系表单,并将此部分的 anchor 指定为 div id="contact"。
当在任何页面上单击联系按钮时,它应该导航到主页并在页面加载时自动滚动到联系表单。
在查看了我在这里找到的类似问题后,我未能成功地使其发挥作用:jQuery scroll to ID from different page当我尝试时,它只是跳转到表单。我希望它能够平滑滚动。
<li><span>Get in touch</span><a href="index.html#contact">Contact</a></li>
问题jquery函数从其他页面滚动到主页上的联系人 anchor :
(function($){
var jump=function(e) {
if (e) {
e.preventDefault();
var target = $(this).attr("href");
} else {
var target = location.hash;
}
$('html,body').animate({
scrollTop: $(target).offset().top
},1000,function() {
location.hash = target;
});
}
$('html, body').hide()
$(document).ready(function() {
$('a[href^=#]').bind("click", jump);
if (location.hash) {
setTimeout(function(){
$('html, body').scrollTop(0).show()
jump()
}, 0);
} else {
$('html, body').show()
}
});
我正在尝试实现与此示例类似的目标:http://vostrel.cz/so/9652944/page.html区别在于,在本例中,“ anchor id”不是出现在两个页面上,而是我的 anchor id(联系人)仅出现在一页(主页)上。
最佳答案
试试这个,你的脚本没问题,只是缺少最后一行
(function ($) {
var jump = function (e) {
if (e) {
e.preventDefault();
var target = $(this).attr("href");
} else {
var target = location.hash;
}
$('html,body').animate({
scrollTop: $(target).offset().top
}, 1000, function () {
location.hash = target;
});
}
$('html, body').hide();
$(document).ready(function () {
$('a[href^=#]').bind("click", jump);
if (location.hash) {
setTimeout(function () {
$('html, body').scrollTop(0).show()
jump();
}, 0);
} else {
$('html, body').show();
}
});
})(jQuery)
关于jquery - 链接到不同页面 -> jquery 滚动到特定 anchor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11820055/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!