固定条形脚本使幻灯片播放"跳跃" - 如何删除?

时间:2015-06-26 16:23:41

标签: javascript html css

我找不到更好的因为它是我网站的特定错误,我会提供一个链接来查看它和他的代码。

问题是当我滚动时,有一个脚本当条形触摸浏览器的顶部时,条形图将保留在那里,但这会使幻灯片显示跳跃并且条形图会切割幻灯片的一部分。 / p>

请在此处查看:http://optential.co.nf/

代码:



html,
body { height: 100%; }

body {
  margin: 0;
  font-family: 'Open Sans', Helvetica, sans-serif;
  min-width: 900px;
}

.header {
  background-image: url("img/fundo1.jpg");
  background-color: rgb(21, 21, 21);
  background-size: cover;
  color: white;
  height: 100%;
  min-height: 650px;
  position: relative;
}

.header .logo {
  width: 230px;
  height: 60px;
  margin: 20px 8px 8px 6%;
}

.header .menu {
  position: absolute;
  top: 55px; right: 25px;
}

.header .menu a {
  margin: 0 4px;
  font-size: 15px;
  color: white;
  text-decoration: none;
  padding: 6px 20px;
}

.header .menu a:hover,
.header .menu a.current {
  color: rgb(204, 66, 63);
}

.header .move {
  color: white;
  width: 40%;
  margin: 0;
  padding: 10px;
}

.header .move .center {
  margin: 260px auto 0;
  width: 360px;
}

.header .move h1 {
  font-weight: 400;
  font-size: 38px;
  margin: 6px 0;
}

.header .move p {
  font-weight: 300;
  font-size: 20px;
  border-top: 2px solid white;
  margin: 6px 0;
  padding-top: 6px;
}

.header .mail1 {
  background-image: url("img/email.png");
  background-size: contain;
  background-position: 100% 100%;
  background-repeat: no-repeat;
  width: 560px; height: 560px;
  position: absolute;
  bottom: 0; right: 0;
}

.header .mail1 form {
  position: absolute;
  width: 240px;
  bottom: 220px; right: 155px;
}

.header .mail1 h1 {
  font-weight: 300;
  text-align: center;
  color: rgb(203, 41, 37);

}
.header .mail1 input {
  box-sizing: border-box;
  width: 100%;
  font-family: 'Open Sans', Helvetica, sans-serif;
  padding: 8px;
  border: 1px solid rgb(219, 219, 218);
  border-radius: 6px;
  margin-bottom: 12px;
 }

.header .mail1 input:hover {
  border: 1px solid rgb(189, 189, 188);
}

.header .mail1 input:focus {
  outline: 0;
}

.header .mail1 a {
  display: block;
  color: white;
  text-decoration: none;
  background-color: rgb(204, 66, 63);
  border-radius: 6px;
  text-align: center;
  padding: 8px;
  font-size: 14px;
}

.header .mail1 a:hover {
  background-color: rgb(224, 86, 83);
}

.mail2 {
  box-shadow: 10px 6px 15px grey;
  background-color: white;
  background-image: url("img/barra.png");
  background-position: 12% 0%;
  height: 100px;
  background-repeat: no-repeat;
  text-align: right;
}

#btn {
    width: 10em; 
  }

.mail2.fixed {
  box-shadow: 10px 6px 15px grey;
  position: fixed;
  display:block;
  top: 0; left: 0;
  width: 100%;
  min-width: 800px;
  height: 100px;
  z-index: 1;
}

.mail2 form {
  display: inline-block;
  margin: 30px 0;
  padding: 0 10px;
  width: 600px;
}

.mail2 h1 {
  font-weight: 300;
  color: rgb(203, 41, 37);
  display: inline;
  vertical-align: middle;
  font-size: 28px;
}

.mail2 input {
  box-sizing: border-box;
  width: 220px;
  font-family: 'Open Sans', Helvetica, sans-serif;
  padding: 8px;
  border: 1px solid rgb(219, 219, 218);
  border-radius: 6px;
  margin: 0 6px;
}

.mail2 input:hover {
  border: 1px solid rgb(189, 189, 188);
}

.mail2 input:focus {
  outline: 0;
}

.mail2 a {
  display: inline;
  color: white;
  text-decoration: none;
  background-color: rgb(204, 66, 63);
  border-radius: 6px;
  text-align: center;
  padding: 8px 4%;
  font-size: 14px;
}

.mail2 a:hover {
  background-color: rgb(224, 86, 83);
}

.mail2 .top {
  padding: 8px 6px;
  background-color: rgb(51, 51, 51);
}

.mail2 .top:hover {
  background-color: rgb(71, 71, 71);
}

#slider {
  position:relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#slider .images { 
  width: 100%;
  position: relative;
  transition: left 1s;
  left: 0;
}

#slider .images img {
  z-index: -1;
  width: 100%;
  background-size: cover;
  position: absolute;
}

.controls {
  width:100%;
  width: 350px;
  margin: 5px auto;
  display: flex;
  justify-content: center;
}

.controls div {

  width: 16px;
  height: 16px;
  margin: 0 5px;
  background: tomato;
  border-radius: 50%;
}

.controls .current {
  background: red;
}

.barra2 {
  background-image: url('img/barra2.png');
  background-size: cover;
  padding-bottom: 21.6%;
}

.mobile {
  background-image: url("img/fundos.jpg");
  background-size: cover;
  background-color: rgb(171, 171, 171);
  color: white;
  padding-bottom: 44.4%;
  position: relative;
}

#pc {
  height: 600px;
  width: 50%;
  float: left;
  background-size: 100%
  background-repeat:no-repeat;
  background-image: url("img/pc.jpg");
}

#pctexto {
  height: 600px;
  width: 50%;
  float: left;
  background-size: cover;
  background-color: blue;
}
.mobile .invisi {
  position: absolute;
  width: 13%;
  height: 10%;
  bottom: 14%;
  border-radius: 8px;
}
.mobile .invisi:hover {
  background: white;
  opacity: 0.2;
}

.mobile .appstore {
  right: 26.5%;
}

.mobile .googleplay {
  right: 11.5%;
}

.contact {
  background-image: url("img/fundo2es.jpg");
  background-size: 100%;
  background-color: rgb(21, 21, 21);
  background-repeat: no-repeat;
  height:100%;
  color:white;
}

.contact .textocon {
  text-align: right;
  padding: 55px 75px 0 0;
}

.contact .textocon div {
  display: inline-block;
  width: 290px
}

.contact .textocon h1 {
  font-weight: 400;
  font-size: 42px;
  margin: 6px 0;
}

.contact .textocon p {
  font-weight: 300;
  font-size: 19px;
  border-top: 2px solid white;
  margin: 6px 0;
  padding-top: 6px;
}

.contact .col1 {
  display: inline-block;
  vertical-align: top;
  width: 410px;
  padding: 10px 6px 10px 60px;
}

.contact .col1 h1 {
  font-weight: 300;
  font-size: 25px;
  margin: 4px 0;
}

.contact .col1 input {
  width: 380px;
  height: 20px;
}

.contact .col1 input,
.contact .col2 textarea {
  font-family: 'Open Sans', Helvetica, sans-serif;
  padding: 14px;
  font-size: 13px;
  color: white;
  background-color: transparent;
  border: 1px solid rgb(172, 161, 160);
  margin: 6px 0;
}
.contact .col1 input:focus,
.contact .col2 textarea:focus {
  outline: 0;
  border: 1px solid white;
}

.contact .col2 {
  display: inline-block;
  width: calc(100% - 560px);
  padding: 52px 10px 10px 0;
  text-align: right;
}

.contact .col2 textarea {
  text-align: left;
  width: 100%;
  box-sizing: border-box;
  height: 112px;
}

.contact .col2 #btn {
  display: inline-block;
  color: white;
  font-weight: bold;
  text-align: center;
  text-decoration: none;
  background-color: rgb(204, 66, 63);
  border-radius: 4px;
  padding: 10px 0px;
  font-size: 20px;
}
.contact .col2 a:hover {
  background-color: rgb(224, 86, 83);
}

.contact .info {
  padding: 10px 60px;
  display: flex;
  justify-content: space-between;
}

.contact .info h1 {
  font-weight: 300;
  font-size: 25px;
}

.contact .info p {
  font-size: 12px;
  line-height: 12px;
}

.contact .info a {
  text-decoration: none;
  color: white;
}
.contact .info a:hover {
  color: #ddd;
}

.contact .info img {
  width: 32px;
  margin: 6px;
}
.contact .info img:hover {
  opacity: 0.8;
}

<!DOCTYPE html>
<html>
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="js/fixedbar.js"></script>
    <script src="js/slider.js"></script>
    <meta charset="utf-8">
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" rel="stylesheet" type="text/css">
    <link href="styles.css" rel="stylesheet" type="text/css">
    <title> Layout </title>
  </head>
  <body>


    <div class="header" id="top">
      <img class="logo" src="img/logo.png">
      <div class="menu">
        <a href="#" class="current">Home</a>
        <a href="#tour">Product Tour</a>
        <a href="#">Pricing</a>
        <a href="#">Try</a>
        <a href="#vision">Vision</a>
      </div>
      <div class="move">
        <div class="center">
          <h1>Move work forward!</h1>
          <p>Optential keeps your team organized, connected, and focused on results.</p>
        </div>
      </div>
      <div class="mail1">
        <form action="form/form.php" method="post">
          <h1>Try Now!</h1>
          <input name="Email" class="Email" type="text" placeholder="Enter your Email address ...">
          <input type="submit" value="Get started for free">
        </form>
      </div>
    </div>

    <div class="mail2">
        <form action="form/form.php" method="post">
        <h1>Try Now!</h1>
        <input type="text" placeholder="Your Email here...">
        <input type="submit" id ="btn" value="Get started for free">
        <a class="top" href="#top">Top</a>
      </form>
    </div>


    <div id="slider">
        <div class="images">
          <div class="controls">
          <img src="img/3.png" alt="Image-1" />
          <img src="img/2.png" alt="Image-2" />
          <img src="img/1.png" alt="Image-3" />
          <img src="img/4.png" alt="Image-4" />
        </div> 
      </div>
    </div>

    <div class="barra2"></div>

    <div class="mobile">
      <div id="pc"> 

      </div>

      <div id="pctexto">

      </div>
    </div>

    <div class="contact">
      <div class="textocon">
        <div>
          <h1>Optential</h1>
          <p>A new management system<br>for a new management paradigm!</p>
        </div>
      </div>
      <form method="POST" action="form/contactengine.php">
        <div class="col1">
          <h1>Contact us!</h1>
          <input type="text" name="Name" size="50" placeholder="Name"/>
          <input type="text" name="Email" size="50" placeholder="Email"/>
          <input type="text" name="Subject" size="50" placeholder="Subject"/>
        </div>
        <div class="col2">
          <textarea name="Message" rows="5" cols="70" placeholder="Message..."></textarea>
          <input type="submit" id="btn"value="Send"/>
        </div>
      </form>
      <div class="info">
        <div>
          <h1>Mail Us !</h1>
          <p>Rua Andrade Corvo, 242</p>
          <p>sala 206</p>
          <p>4700-204 Braga</p>
          <p>Portugal</p>
        </div>
        <div>
          <h1>Call Us !</h1>
          <a href="#"><p>+351 987654323</p></a>
          <a href="#"><p>+351 987654323</p></a>
          <a href="#"><p>+351 987654323</p></a>
        </div>
        <div>
          <h1>Email Us! </h1>
          <a href="#"><p>code@angel.com</p></a>
          <a href="#"><p>code_hr@angel.com</p></a>
          <a href="#"><p>code_support@angel.com</p></a>
        </div>
        <div>
          <h1>Join Us! </h1>
          <a href="#"><img src="img/facebook.png"></a>
          <a href="#"><img src="img/gplus.png"></a>
          <a href="#"><img src="img/twitter.png"></a>
          <a href="#"><img src="img/instag.png"></a>
        </div>
      </div>
    </div>
<script src="js/slider.js"></script>
  </body>
</html>
&#13;
import re
str = '<img title="\\small \\frac{4}{5}" src="http://latex.codecogs.com/gif.latex?\\small&amp;space;\\frac{4}{5}" alt="" width="4" height="16" />'
p = re.compile('img\b[^<]*(?<=title=")\\frac\{(\d+)\}\{(\d+)\}"[^<]*>')
print p.match(str)
&#13;
&#13;
&#13;

栏的css是&#34;邮件2&#34;,幻灯片是&#34;滑块&#34;和&#34;控制&#34;。

希望有人可以提供帮助。

3 个答案:

答案 0 :(得分:3)

当您应用.fixed时,您将从流程中取出菜单元素。这是因为它从position: relative更改为position: fixed。这就是为什么它下面的元素跳了100px。要完成您所需的效果,您需要补偿丢失的100px。

选项1

您可以将margin-top应用于以下#slider元素:

if ($(window).scrollTop() > h) {
   $('.mail2, .optimize').addClass('fixed');
   $('#slider').css('margin-top', '100px');

} else {
  $('.mail2, .optimize').removeClass('fixed');
  $('#slider').css('margin-top', '0px');
}

选项2

您可以在流程中添加100px高度的元素。

在您的HTML中,将其添加到.mail2元素

下方
<div id="menu-block" style="height: 100px; display: none;">

并将其添加到您的JS:

if ($(window).scrollTop() > h) {
  $('.mail2, .optimize').addClass('fixed');
  $('#menu-block').css('display', 'block');

} else {
  $('.mail2, .optimize').removeClass('fixed');
  $('#menu-block').css('display', 'none');
}

在这种特殊情况下,两种方式都是一样的。在其他情况下,只有一种技术是合适的。希望这有帮助!

答案 1 :(得分:2)

考虑到条形是100px的固定高度,您可以添加如下规则:

.fixed + #slider {
  padding-top: 100px;
}

或者如果其他页面具有更多动态布局,您可以使用.fixed + *

答案 2 :(得分:2)

这是因为只要你成为position:fixed它就不再占用页面上的空间,所以它下面的内容会跳起来填补空间。

我过去曾经遇到过这种情况,而我的解决方案是在另一个div下面修复一下这个问题。它需要与将要固定的div相同的高度。将其设为display:none,然后在切换要修复的栏时将其更改为display:block,这样当固定栏停止占用页面空间时,它就会出现。这应该阻止它跳跃。