【问题标题】:Change position according to the scroll根据滚动改变位置
【发布时间】:2016-08-02 13:17:23
【问题描述】:

我想根据我的滚动更改位置。 因为图片能说出一千个字,这就是我想要的:

这是我的代码:https://jsfiddle.net/njz87Lth/1/

html:

<h1> MY TEXT. orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </h1>
<div class="one"> </div>
<div class="two"> </div>

css:

body {
  text-align:center;
}

h1 {
  left: 0;
  line-height:2;
  right:0;
  width:600px;
  margin-left: auto;
  margin-right: auto;
  position:fixed;
}

.one, .two {
  width:600px;
  position: absolute;
  left: 0;
  right:0;
  margin-left: auto;
  margin-right: auto;
}

.one {
    top:100px;
    height:300px;
    background:grey;
}

.two {
    height:800px;
    background:pink;
    margin-top:30px;
    top:400px;
}

【问题讨论】:

    标签: jquery html css scroll position


    【解决方案1】:

    使用 jQuery 试试这个。

    $(window).scroll(function () { 
         $(".one").offset({ left: left, top: top});
    
    });
    

    根据您的需要给offset 值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 2013-10-02
      相关资源
      最近更新 更多