jquery - 根据滚动改变位置

标签 jquery html css scroll position

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

enter image description here

这是我的代码: 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>

样式:

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 试试这个。

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

});

根据您的需要给 offset 值。

关于jquery - 根据滚动改变位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38721536/

相关文章:

以编程方式创建 <img> 时的 Javascript onmouseover 和 onmouseout

PHP 和 MySQL : retrieving data from a database based on the link a user clicks

html - 仅在移动浏览器上按钮之间有额外间距

Javascript 和按钮切换

HTML 电子邮件模板 Mailchimp、Outlook 和 Gmail 中的 CSS 问题

javascript - 如何使用 URL 重写在 javascript 中访问 REAL querystring 参数

html - 如何使用css超时改变球体的位置

html - 如何去除点击图片后显示的边框

javascript - ChartJS 设置 yAxes "ticks"

javascript - 根据选择选项更新多个单选按钮