Scroll page parallax when I click on navigation menu (Parallax Scrolling)

好久不见. 提交于 2020-01-03 03:36:05

问题


Sorry If my tone is not good, I am using this code in a web page.

HTML:

<a class="second" href="#nav1">Home</a>
<a class="second" href="#nav2">About</a>
<a class="second" href="#nav3">Contact</a>

<section id="nav1" data-speed="4" data-type="background">
  <article>Big Tech Ideas Page3</article>
</section>

<section id="nav2" data-speed="4" data-type="background">
  <article>Big Tech Ideas Page3</article>
</section>

<section id="nav3" data-speed="4" data-type="background">
  <article>Big Tech Ideas Page3</article>
</section>

Question: my question is this, When I click on link "About" of "Contact", page should scroll slowly slowly . NOTE:(Here I mean Parallax Scrolling).

suggest me css for this.


回答1:


You're gonna have to modify your HTML. I passed across a solution some time ago but I don't remember where it is. Anyway here's how I'd modify your code:

HTML:

<a id="nav1"></a>
<a id="nav2"></a>
<a id="nav3"></a>
<header class="nav">
    <nav>
        <ul>
            <li><a href="#nav1">Home</a> </li>
            <li><a href="#nav2">About</a></li>
            <li><a href="#nav3">Contact</a></li>
        </ul>
    </nav>
</header>

<section id="main">
    <article class="article" id="nav1">
        <p>Big Tech Ideas Page3</p>
    </article>

    <article class="article" id="nav2">
        <p>Big Tech Ideas Page3</p>
    </article>

    <article class="article" id="contacto">
        <p>Big Tech Ideas Page3</p>
    </article>
</section>

CSS:

a[id= "nav1"]:target ~ #main article.article {
    -webkit-transform: translateY( 0px);
    transform: translateY( 0px );
}

a[id= "nav2"]:target ~ #main article.article {
    -webkit-transform: translateY( -500px );
    transform: translateY( -500px );
}
a[id= "nav3"]:target ~ #main article.article {
    -webkit-transform: translateY( -1000px );
    transform: translateY( -1000px );
}

header {
    position: fixed; 
    z-index: 10; 
}

.article {
    width: 100%;
    height: 600px;
    z-index:0; 
    -webkit-transform: translateZ( 0 );
    transform: translateZ( 0 );
    -webkit-transition: -webkit-transform 2s ease-in-out;
    transition: transform 2s ease-in-out;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.article p {
    font-family: sans-serif;
    font-size: 86px;
    font-size: 5rem;
    position:relative;
    line-height: 300px;
    text-align: center;
    margin: 0;
}

Let me know if it works.

Working demo fiddle: http://jsfiddle.net/Fraximus/CFSEK/1/




回答2:


Is there any way to produce reverse-parallax scrolling? i.e. On scrolling the content down, I want the respective title in the left pane to get highlighted accordingly.



来源:https://stackoverflow.com/questions/18888413/scroll-page-parallax-when-i-click-on-navigation-menu-parallax-scrolling

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