简体   繁体   English

滚动到顶部按钮并打开新页面

[英]Scroll To Top Button and open new page

I want, When I click on a button to go to the top and change the page. 我想要,当我单击按钮转到顶部并更改页面时。

I have this 我有这个

code js> 代码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;
    });

code html> 代码html>

<a href="<?php $url->_getURL('openpage'); ?>" class="scrollToTop">Domestic Electrical installation</a>

thank you for your help 谢谢您的帮助

What you want to do is use the scrollTo() method and navigator.href property. 您要做的是使用scrollTo()方法和navigator.href属性。

Try this: 尝试这个:

//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
}

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM