为javascript中的html标记设计的调用函数
我在网上找到了一个功能,它可以使我的标签中的href滚动显示,而不是仅仅显示在那里:为javascript中的html标记设计的调用函数,javascript,html,Javascript,Html,我在网上找到了一个功能,它可以使我的标签中的href滚动显示,而不是仅仅显示在那里: $(function () { var headerHeight = 70; $('a[href*=#]:not([href=#])').click(function () { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostn
$(function () {
var headerHeight = 70;
$('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 - headerHeight
}, 1000);
return false;
}
}
});
});
现在我需要使用javascript代码到达页面中的某个位置,因为我遇到了一个尴尬的情况,表单提交按钮也应该滚动到某个位置:
<div
value="GO"
id="go-div"
class="bubble">
<input type="submit"
value="GO"
id="go-button"
style=" position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;"
onclick="location.href='#search-results-page';">
</input>
</div>
那么如何更改位置。href='search-results-page';要使用滚动功能,请使用多种方法。以下是一个例子: 按钮:
<input style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;"
type="submit"
data-target="#search-results-page"
value="GO"
id="go-button">
我认为这是一个非常优雅的解决方案,能够简单地向需要在单击时滚动到某个位置的元素添加数据目标属性+1.谢谢
<input style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;"
type="submit"
data-target="#search-results-page"
value="GO"
id="go-button">