Smooth slide transition between two separate html files

耗尽温柔 提交于 2019-12-25 06:39:18

问题


is there any possibility to make smooth slide transition between two seperate html files? Like for example. On one html is

<a href="secondHtml.html">Link</a>

and after clicking this link page is not reloading, just sliding to the second file?


回答1:


You have to load the second HTML file into an iFrame or into a DIV by ajax, then slide it into view. You can use jQuery for that and for easy access to animations.

You may also would like to update the URL of your page, for that you can use location.hash to do it without reloading the page. You can also check for observehashchange plugin for jquery to check for the hash change when a user changes the URL.

You can view a sample here.

To have Google access the pages, you can add a sitemap.xml to your site to describe the pages and you may also have to setup webmaster tools to provide Google with useful information about your site. Here you can add the links and Google will got it. I have a page where more than 5000 links are seen by Google, however they aren't on any page by default.

But if you want to have normal <a> links on your page, you can use a simple jQuery to trigger the animation instead of going to the link.

<a href="/page2">Go to page 2</a>
<a href="/page3">Go to page 3</a>
<a href="/page4">Go to page 4</a>
<script>
    function LoadPage(page) {
        //Put your page loader script here        
    }

    $(document).ready(function(){
        $(a).click(function(event){
            event.preventDefault();
            var page = $(this).attr('href').substr(1);
            LoadPage(page);
        });
    });
</script>


来源:https://stackoverflow.com/questions/31899278/smooth-slide-transition-between-two-separate-html-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!