滚动到顶部按钮并打开新页面
问题描述:
我想要的,当我点击一个按钮去顶部并更改页面。滚动到顶部按钮并打开新页面
我有这个
代码的js>
$(document).ready(function(){
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
代码的html>
<a href="<?php $url->_getURL('openpage'); ?>" class="scrollToTop">Domestic Electrical installation</a>
感谢你的帮助
答
你想要做的是使用scrollTo()
方法和navigator.href
财产。
试试这个:
//with JQuery:
$(".scrollToTop").click(function(){
window.scrollTo(0,0); //Scrolls to a x,y pair(x = vertical y = horizontal
navigator.href = newURL; //Sets the page of the current tab to a url value
}
你可以写给我完整的代码.. iam不是很好..让自己.. tnx – user3480332 2014-10-28 22:54:16
当然...我会编辑我的答案是更广泛的。 – DripDrop 2014-10-28 22:55:13
那里。我编辑了代码,现在可以使用它来代替点击处理事件。很高兴我能帮上忙。 – DripDrop 2014-10-28 23:00:04