当用户转到另一个页面并返回时,如何同步所有动画?

时间:2019-06-06 12:50:35

标签: jquery html css

当我转到另一页并返回首页时,变色文本似乎不同步。我在页眉和页面的其余部分之间看到了这种情况,但是,另一页上的内容似乎与页眉同步,因此我猜这是第一页上的动画。

我尝试重做动画并使文本以不同的方式更改颜色,但是我仍然看到此问题。

HTML和JQuery

  <head>
  <link rel="stylesheet" type="text/css" href="website.css">
  <link href="https://fonts.googleapis.com/css?family=Crimson+Text|Montserrat" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css">
  </head>
  <body>
    <div class="banner">
  <ul>
    <li>
      <h1 class="animated fadeIn">SILVER · SPOON</h1>
    </li>
    <a class='page-button' data-page_num='1' href='javascript:voide(0)'>
      <li class="main-button home-button">Home</li>
    </a>
    <a class='page-button' data-page_num='2' href='javascript:voide(0)'>
      <li class="main-button about-button">Drinks Menu</li>
    </a>
    <li class="main-button about-button" data-page_num='3'>Food Menu</li>
    <a class='page-button' data-page_num='5' href='javascript:voide(0)'>
      <li class="main-button about-button">About</li>
     </a>
  </ul>



</div>
<div class="page">
  <div id="Home">
  <div class="content1">
  <div class="container">

  </div>
  </div>
    <div class="content2">
      <div class="container">
      <a class='page-button' data-page_num='2' href='javascript:voide(0)'>
        <h3>Menu</h3>
      </a>
        <h4>Now introducing edible food.</h4>
        <p>Silver Spoon has a high-quality menu with affordable prices. Find out more on the menu page.</p>
      </div>
      <div class="content1">
        <div class="container">
          <h3>About</h3>
          <p>Read more about Silver Spoon on our about page.</p>
        </div>
      </div>
    </div>
  </div>
  </div>
</div>
  <div class="page">
    <div id="Drinks Menu">
    <ul class="menu-list">
  <li class="li"><span class="title">Cafe Americano</span><span class="price">3<sup>99</sup></span></li>
  <li class="li"><span class="title">Iced Latte</span><span class="price">4<sup>99</sup></span></li>
  <li class="li"><span class="title">Caramel Macchiato</span><span class="price">5<sup>50</sup></span></li>
      <li class="li"><span class="title">Espresso</span><span class="price">4<sup>50</sup></span></li>
      <li class="li"><span class="title">Blonde Roast</span><span class="price">3<sup>00</sup></span></li>
      <li class="li"><span class="title">Iced Coffee w/ Milk</span><span class="price">4<sup>00</sup></span></li>
      <li class="li"><span class="title">Cold Brew w/ Foam</span><span class="price">4<sup>50</sup></span></li>
      <li class="li"><span class="title">Dark Roast</span><span class="price">3<sup>00</sup></span></li>
      <li class="li"><span class="title">Hot Chocolate</span><span class="price">4<sup>00</sup></span></li>
    </div>
  </div>
  </div>
  <div class="page">
</body>


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <!--script that shouldn't be changed-->
    <script>
        //hide all the pages and display the home page
        $('.page').hide();
        $($('.page')[0]).show();
        $($('.page-button')[0]).addClass('selected');

        //this block of code switches the pages. it works no matter how many pages or page buttons there are, making it easy to add and remove pages
        $('.page-button').on('click', function() {
        $(this).addClass('selected');
        $('.page').hide();
        $($('.page')[parseInt($(this).attr('data-page_num')) - 1]).show(); //displays the page based on the value of data-page_num
        window.scrollTo(0, 0); //scroll to the  top of the page
        });

    </script>
  </div>
</body>
</html> 

CSS

body, a {
  background: #dcdcdc;
  font-family: 'Montserrat', sans-serif;
  font-weight: 300;
  margin: 0px;
}

p, h1 {
    font-family: 'Crimson Text', Serif;
}

ul, li {
  list-style-type: none;
}

ul li {
  display: inline-block;
  box-sizing: border-box;
  text-align: left;
}

.main-button {
  display: inline-block;
  width: 79px;
  padding: 10px;
  box-sizing: border-box;
  text-align: center;
  font-size: 16px;
}

.main-button:hover {
  background: rgba(255, 255, 255, 0.1);
  transition: 1s;
  cursor: pointer;
}

h3 {
  text-align: center;
  font-size: 44px;
}

.container {
  box-sizing: border-box;
  margin: auto;
  max-width: 70%;
  padding: 20px;
}

.button {
  display: inline-block;
  width: 130px;
  margin: 10px;
  padding: 10px;
  text-align: center;
  text-decoration: none;
}

.button:hover {
  background: rgb(0, 105, 242);
  transition: 0.25s;
  color: white;
  cursor: pointer;
}

a {
  text-decoration: none;
}

a:hover {
  color: white;
  transition: 0.5s;
}

.content1 {
  background: rgba(255, 255, 255, 0.15);
}

.content2 {
  background: rgba(255, 255, 255, 0.1);
}

@keyframes example {
    0%   {color: #e91e63;}
    14%  {color: #e74c3c;}
    28%  {color: #f1c40f;}
    42% {color: #2ecc71;}
    56% {color: #3498db;}
    72% {color: #71368a;}
    86% {color: #9b59b6;}
    100%   {color: #91e63;}
}

body, a {
    color: red;
    animation-name: example;
    animation-duration: 10s;
    animation-iteration-count: infinite;
}

.menu-list {
  list-style-type: disc;
  margin-block-start: 0;
  margin-block-end: 0;
  margin-inline-start: 0;
  margin-inline-end: 0;
  padding-inline-start: 0;
}

.menu-list .li {
  margin: auto;
  display: flex;
  width: 60%;
  /* 'justify-content: space-between;' does the trick of
  separating the two items in the li */
  justify-content: space-between;
  border-bottom: 1px dotted;
}

.menu-list .li .title,
.menu-list .li .price {
  display: flex;
}

.menu-list .li .title {
  font-size: 18px;
  align-self: flex-end;
}

.menu-list .li .price {
  font-size: 30px;
}

我只是希望颜色在不同页面上保持同步,无论是通过单击新页面时动画重置还是将其保留。

0 个答案:

没有答案