gpt4 book ai didi

javascript - Jquery平滑滚动(非锚定)

转载 作者:行者123 更新时间:2023-12-03 11:13:11 25 4
gpt4 key购买 nike

我在这里看过几篇文章,但我找不到正确的答案。我不是在寻找平滑滚动到 anchor ,我已经得到了,我正在寻找像 this 这样的平滑滚动或this 。不知怎的,他们都使用 this jquery,我不知道如何实现。

我已经尝试过这个:simplr-smoothscroll 。但这个并不是真的那么“平滑”,当你快速滚动时,它会减慢你的速度。

我也尝试过:simple smooth-wheel 。但我无法正确实现这一点,因为我的高度设置为 100%,其他人也在 github 上提示了这一点。除此之外,下载中提供的演示(不在 github 上)对我来说也不起作用,尝试修复该演示,但仍然没有成功。

我也尝试使用该源:smoothwheel 。然而我不是一个 javascript 魔术师,所以我无法完成这个任务。

这是我的简单 jsfiddle 页面,它应该在其中工作:jsfiddle

 <div id="menubar">
<a href="#welcome">Welcome</a><a href="#welcome">Welcome</a><a href="#welcome">Welcome</a><a href="#welcome">Welcome</a>
</div>
<div id="container">
<div id="content">
<br />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum a tortor fringilla, volutpat justo malesuada, suscipit justo. Fusce ante dui, bibendum non sapien vitae, hendrerit ultricies enim. Quisque dictum fermentum congue. Vestibulum posuere iaculis arcu, ultrices pharetra mauris ultrices finibus. Ut pulvinar sit amet justo et rhoncus. Maecenas id ante vel tortor vulputate commodo in in lacus. Nunc auctor vulputate ornare. Donec lacus odio, maximus ut massa a, finibus pulvinar justo. In facilisis quam sed pharetra aliquet. Etiam varius non eros non suscipit. Vestibulum venenatis placerat accumsan. Nulla nec consequat mauris. Etiam nisl magna, semper vel sem mollis, vehicula bibendum urna. Nunc porttitor dui sed volutpat imperdiet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus pharetra ligula sit amet sapien mollis malesuada.

Sed mollis convallis risus. Duis volutpat, diam rutrum pretium scelerisque, odio nunc faucibus odio, sit amet cursus justo justo ac mi. Aenean laoreet et eros non viverra. Praesent id erat vel nisl molestie pharetra. Pellentesque eu eros nibh. Aliquam mollis, tortor eget consequat varius, metus sapien suscipit nisl, eu convallis ligula orci eu erat. Fusce et ex dignissim eros porta eleifend in quis sapien. Suspendisse potenti. Quisque non vehicula mauris, eget ornare tellus. Pellentesque aliquet massa augue, sed hendrerit massa condimentum eget. Nunc vulputate neque nunc, ac interdum velit tristique sed. Donec vestibulum nibh at tellus condimentum, sed rutrum quam pellentesque. Mauris congue blandit justo, a auctor est. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse et sem vulputate, malesuada lectus ultrices, luctus elit.

Ut enim metus, lobortis in malesuada sed, fringilla sit amet velit. Phasellus nec tincidunt risus. Nam id nulla et dolor tempor consectetur elementum sit amet lacus. Nunc non felis enim. Curabitur feugiat at quam ac auctor. Duis nibh enim, consequat id sagittis vitae, pharetra nec arcu. Pellentesque vitae nisl tincidunt purus faucibus dignissim ut egestas enim. Integer gravida suscipit interdum. Nunc ac tellus urna. Proin odio quam, pulvinar sed tristique sed, viverra sed mi. Phasellus dapibus ipsum in tempor aliquet. Nam a lectus eu purus volutpat sodales eu at ante. Duis quis scelerisque lectus. Mauris interdum massa quis nisi luctus tincidunt. Etiam ut varius arcu, venenatis lacinia nulla. Cras tristique porta accumsan.

Nam dignissim risus tellus, sit amet faucibus mi dignissim eget. Sed luctus dolor et augue convallis tristique. Etiam sed urna urna. Etiam id lacinia neque. Aliquam ac sapien lacus. Ut lacus quam, efficitur a orci a, gravida porttitor dui. Nunc eget augue vehicula, congue mi ultrices, tempus neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

Nullam at venenatis ante. Ut odio justo, auctor non lacinia at, sollicitudin vel augue. Pellentesque urna felis, posuere sit amet lacus fermentum, congue dignissim elit. Phasellus eleifend lectus vitae arcu tristique, et pellentesque nunc venenatis. Duis at est velit. Nullam vestibulum lorem auctor vestibulum ornare. Mauris sed libero ut libero pellentesque fermentum eget eu nisi. Nam augue dolor, mollis ut volutpat eget, vulputate sit amet nisl. Etiam at elit dapibus, laoreet est at, sagittis nisl. Pellentesque sed risus in quam pretium porta sed vitae velit. Phasellus risus odio, imperdiet vel vulputate eget, imperdiet eu nisl. Aliquam ultrices lorem nec aliquet consectetur.</p>
<br />
</div>
<div id="img2">
<img src="someImage.png" />
</div>

CSS:

body {
min-width:800px;
margin: 0;
background-color:blue; <!--this is a image -->
background-size: 100% auto;
background-attachment:fixed;
height:100%;

}

#menubar{
position:fixed;
top:5px;
right:0;
background-color:none;
height:auto;
z-index:1;
}


#container{
position:absolute;
top:75%;
}

#content{
width:100%;
background-color:white;
margin:0;
}


#img2{
width:100%;
margin:0;
}

#img2 img{
width:100%;
}

最佳答案

example您给出的信息是,他们正在使用 IntelliJ IDEA 的 jquery.smoothwheel

检查这个link 。也许这就是您正在寻找的效果。

希望有用!

由OP编辑:

在@Academia 给了我这个 fiddle 之后,我设法让它满足我的需求。

这就是我最终得到的结果:

CSS:

body {
background: url(someImage.png);
background-size: 100% auto;
background-attachment:fixed;
margin: 0 auto;
width:100%;
height:1000px; /*key value to make this script work, else it only scrolls smoothly when your mouse is hovering over the #container*/
overflow:auto;
-webkit-overflow-scrolling: touch;
position:relative;

}

#container{
width:100%;
background-color:white;
position:absolute;
top:700px; /*I intent to scroll the content over the bg image, that was my struggle, I had it in procentage first*/
}

#content{
width:100%;
background-color:white;
margin:0;
}

html:

<body>   

<div id="container">
<div id="content">
<p>some content</p>
</div>
</div>
</body>

现在对于 javascript,我必须添加一个函数来保持容器的 top 值与屏幕宽度正确

平滑滚动脚本:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="js/jquery.smoothwheel.js"></script>

<script>

$(document).ready(function () {
$("body").smoothWheel()
});

</script>

容器top值的脚本,0.36,因为1920/700 = 0.36,这取决于您想要的top值有:

<script type="text/javascript">
$(document).ready(function () {
var jqeuryElem = jQuery("#container");
var w = $(window).width();
var top = w *0.36;

jqeuryElem.css("top", top+"px");


});
$(window).resize(function () {
var jqeuryElem = jQuery("#container");
var w = $(window).width();
var top = w * 0.36;

jqeuryElem.css("top", top + "px");
});
</script>

网站完成后我会发布结果。

关于javascript - Jquery平滑滚动(非锚定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27463511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com