- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作一个网站,我将在其中使用 Horizontal Scroll
。我正在使用 jQuery.nicescroll
来实现平滑滚动。
$(function() {
var scroll = $(window).scrollLeft();
if (scroll >= 0) {
$('#animateBtn').click(function(){
$('.section-parent').addClass('half');
// Smooth Scroll
$('#js-slideContainer').niceScroll({
cursorwidth: "0px",
cursorborder: "5px solid transparent",
scrollspeed: 260,
smoothscroll: true
});
});
}
// Custom Cursor
var follower, init, mouseX, mouseY, positionElement, printout, timer;
follower = document.getElementById('follower');
printout = document.getElementById('printout');
mouseX = (function(_this) {
return function(event) {
return event.clientX;
};
})(this);
mouseY = (function(_this) {
return function(event) {
return event.clientY;
};
})(this);
positionElement = (function(_this) {
return function(event) {
var mouse;
mouse = {
x: mouseX(event),
y: mouseY(event)
};
follower.style.top = mouse.y + 'px';
return follower.style.left = mouse.x + 'px';
};
})(this);
timer = false;
window.onmousemove = init = (function(_this) {
return function(event) {
var _event;
_event = event;
return timer = setTimeout(function() {
return positionElement(_event);
}, 1);
};
})(this);
});
* {
box-sizing: border-box;
}
html, body {
height: 100%;
width: 100%;
}
body {
padding: 100px;
margin: 0;
background: #e2e1dc;
}
::-webkit-scrollbar {
display: none;
}
.card {
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
.section-parent {
width: 87.5vw;
height: calc(100vh - 12.5vw);
margin-right: 6.25vw;
margin-bottom: 0;
transition: width 1.6s cubic-bezier(.73,.01,.36,.99);
position: relative;
z-index: 2;
flex: 0 0 auto;
}
.section-bg {
background: url("https://via.placeholder.com/700x300") center center no-repeat;
background-size: cover;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.half {
width: 49.7792vh;
}
.section {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
}
.grey {
background-color: #bfbeb7;
}
.green {
background-color: green;
}
.white-smoke {
background-color: white-smoke;
}
.caption {
text-align: center;
}
/*** Cursor ***/
html {
cursor: none;
}
#follower {
position: absolute;
top: 50%;
left: 50%;
z-index: 3;
pointer-events: none;
}
#follower #circle1 {
position: absolute;
-webkit-animation: pulse 2s infinite;
animation: pulse 2s infinite;
background: #fff;
border-radius: 50%;
height: 0em;
width: 0em;
margin-top: 0em;
margin-left: 0em;
}
#follower #circle2 {
position: absolute;
-webkit-animation: pulse 4s infinite;
animation: pulse 4s infinite;
background: rgba(200,0,0,0.8);
border-radius: 50%;
height: 0em;
width: 0em;
margin-top: 0em;
margin-left: 0em;
}
@-moz-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@-webkit-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@-o-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://nicescroll.areaaperta.com/wp-content/plugins/jnicescroll/js/jquery.nicescroll.min.js"></script>
<div id="follower">
<div id="circle1"></div>
<div id="circle2"></div>
</div>
<div class="card" id="js-slideContainer">
<div class="section-parent">
<div class="section-bg">
<button type="button" id="animateBtn" class="animateBtn">Click Here</button>
</div>
</div>
<div class="section grey">
<div class="caption">
<h2>Some Heading</h2>
<P>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</P>
</div>
</div>
<div class="section green">
<div class="caption">
<h2>Other Heading</h2>
<P>Error explicabo architecto iure, numquam quisquam dolores itaque quos aliquid laudantium eaque, voluptas.</P>
</div>
</div>
</div>
为了更好地理解,请在 Full View
中打开代码段。
这是 Fiddle
正如你在演示中看到的那样
.section-parent
将在 button
单击时添加一个类 .half
。我想要的是在用户滚动回最左边时删除 .half
类,然后在滚动时再次添加类 .half
。这次动画应该在 button
上没有 click
的情况下执行。
引用,请查看此网站:villafeltrinelli
最佳答案
我添加了一个滚动功能并修改了你的滚动选择器
$(function() {
var scroll = $("#js-slideContainer").scrollLeft();
if (scroll >= 0) {
$('#animateBtn').click(function(){
$('.section-parent').addClass('half');
// Smooth Scroll
$('#js-slideContainer').niceScroll({
cursorwidth: "0px",
cursorborder: "5px solid transparent",
scrollspeed: 260,
smoothscroll: true
});
});
}
$("#js-slideContainer").scroll(function() {
if ($("#js-slideContainer").scrollLeft() == 0) {
$('.section-parent').removeClass('half');
} else {
$('.section-parent').addClass('half');
}
});
// Custom Cursor
var follower, init, mouseX, mouseY, positionElement, printout, timer;
follower = document.getElementById('follower');
printout = document.getElementById('printout');
mouseX = (function(_this) {
return function(event) {
return event.clientX;
};
})(this);
mouseY = (function(_this) {
return function(event) {
return event.clientY;
};
})(this);
positionElement = (function(_this) {
return function(event) {
var mouse;
mouse = {
x: mouseX(event),
y: mouseY(event)
};
follower.style.top = mouse.y + 'px';
return follower.style.left = mouse.x + 'px';
};
})(this);
timer = false;
window.onmousemove = init = (function(_this) {
return function(event) {
var _event;
_event = event;
return timer = setTimeout(function() {
return positionElement(_event);
}, 1);
};
})(this);
});
* {
box-sizing: border-box;
}
html, body {
height: 100%;
width: 100%;
}
body {
padding: 100px;
margin: 0;
background: #e2e1dc;
}
::-webkit-scrollbar {
display: none;
}
.card {
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
.section-parent {
width: 87.5vw;
height: calc(100vh - 12.5vw);
margin-right: 6.25vw;
margin-bottom: 0;
transition: width 1.6s cubic-bezier(.73,.01,.36,.99);
position: relative;
z-index: 2;
flex: 0 0 auto;
}
.section-bg {
background: url("https://via.placeholder.com/700x300") center center no-repeat;
background-size: cover;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.half {
width: 49.7792vh;
}
.section {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
}
.grey {
background-color: #bfbeb7;
}
.green {
background-color: green;
}
.white-smoke {
background-color: white-smoke;
}
.caption {
text-align: center;
}
/*** Cursor ***/
html {
cursor: none;
}
#follower {
position: absolute;
top: 50%;
left: 50%;
z-index: 3;
pointer-events: none;
}
#follower #circle1 {
position: absolute;
-webkit-animation: pulse 2s infinite;
animation: pulse 2s infinite;
background: #fff;
border-radius: 50%;
height: 0em;
width: 0em;
margin-top: 0em;
margin-left: 0em;
}
#follower #circle2 {
position: absolute;
-webkit-animation: pulse 4s infinite;
animation: pulse 4s infinite;
background: rgba(200,0,0,0.8);
border-radius: 50%;
height: 0em;
width: 0em;
margin-top: 0em;
margin-left: 0em;
}
@-moz-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@-webkit-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@-o-keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
@keyframes pulse {
0% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
50% {
opacity: 0.9;
height: 3em;
width: 3em;
margin-top: -1.5em;
margin-left: -1.5em;
}
100% {
opacity: 0.2;
height: 1em;
width: 1em;
margin-top: -0.5em;
margin-left: -0.5em;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://nicescroll.areaaperta.com/wp-content/plugins/jnicescroll/js/jquery.nicescroll.min.js"></script>
<div id="follower">
<div id="circle1"></div>
<div id="circle2"></div>
</div>
<div class="card" id="js-slideContainer">
<div class="section-parent">
<div class="section-bg">
<button type="button" id="animateBtn" class="animateBtn">Click Here</button>
</div>
</div>
<div class="section grey">
<div class="caption">
<h2>Some Heading</h2>
<P>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</P>
</div>
</div>
<div class="section green">
<div class="caption">
<h2>Other Heading</h2>
<P>Error explicabo architecto iure, numquam quisquam dolores itaque quos aliquid laudantium eaque, voluptas.</P>
</div>
</div>
</div>
关于javascript - 使用 nicescroll 在水平滚动的元素上切换类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54479584/
我目前正在研究一个项目欧拉问题(www.projecteuler.net),但遇到了一个绊脚石。其中一个问题提供了一个 20x20 的数字网格,并要求直线上 4 个数字的最大乘积。这条线可以是水平的、
我有两个表,我需要从每个表中选择一列。 这必须在单个查询中完成。 好消息是这两列以正确的方式排序,并且它们都包含相同数量的行。 现在,我知道我可以通过 rowid 加入两个表,但它很慢,因为它必须进行
我想在我的 iPad 应用程序中实现一个布局,该布局具有一个可左右滚动而不是上下滚动的合适 View : 所以而不是 第 1 行第 2 行第 3 行(垂直滚动)这将是 :第 1 行、第 2 行、第 3
我有五个尺寸的图像:600x30、600x30、600x30、600x30、810x30。它们的名称分别是:0.png、1.png、2.png、3.png、4.png。 如何使用 ImageMagic
我正在寻找一个选项来滚动多个列表(水平),如附件中的图片所示。您可以向左或向右滑动以进入下一个 ListView 。顶部应该有一些按钮可以单击或滚动 我尝试将 ListViews 放入类似此代码的内容
这些值之间是否存在数学关系?如果我知道 hFOV 和 vFOV,我可以计算对角 FOV 而不涉及焦距等其他值吗? 我的第一个想法是使用毕达哥拉斯定理,但也许这是错误的。 最佳答案 感兴趣的物理量是传感
我正在尝试在 game_width=640 和 game_height=480 的窗口内绘制网格。网格单元的数量是预定义的。我想在水平和垂直方向上均匀分布单元格。 void GamePaint(HDC
你好,我已经发布了我的 iphone 应用程序 Micro-Pitch,现在正在将它移植到 android 上。我不知道如何在 ScrollView 中画线,想知道我做错了什么。 这是我的 Scrol
如果您访问我的网站:www.ryancoughlin.com - 如果您在页面右侧看到 Google、Yahoo 等 RSS 按钮。我试图让它们均匀对齐,它们的图像高度都相同,我一直试图让它们均匀对齐
我想将此 Material 水平居中: 最佳答案 将 text-align:center 添加到您的 anchor 。我假设您的 zoom1 具有 display
我正在努力做到这一点,以便我的旋转木马可以与其他文本共享一个水平行,但由于某种原因它无法正常工作,当它设置为 40% 时它占据了 100% 的宽度。 我将在下面发布代码和屏幕截图。 在上图中,它显示了
问题来了。我正在尝试放置一些 彼此相邻的元素。 div 的宽度s 未指定,取决于它们的内容。我正在使用下面的 CSS 代码来定位 彼此相邻: #div{ height: 50px; f
我正在尝试使用这样的 Bootstrap 并排打印表格 但是当我尝试打印预览时,我得到了这个 我的代码如下。我尝试了所有可能的解决方案,但我不知道为什么我无法打印我看到的页面。请指导我解决这个问题。
我想知道是否可以在背景中使用两种不同的颜色,并通过 Bootstrap 在每一侧扩展 100%。 这是我的意思的截图, 左侧为红色,右侧为深色,为更大的屏幕放大 100%。有什么简单的解决方案吗? 最
我正在尝试制作一个包含所有事件的滚动触发的整个网站。我只需要帮助来实现这种效果: 我有一个网站,其中包含一些填满所有视口(viewport)的 div,我希望用户能够向下滚动到一个命名的 div,然后
我的代码是 Show All Show Valid Show Pending Save Clear Download As CSV 我希望那些输入日期和按钮在 class="buttons" di
我在玩这个想法: 在这个 block 中我有 2 作为按钮和 并尝试了 float荷兰国际集团他们让他们粘在一起。实现这种效果的主要思想是操纵 ul 的宽度/显示状态。或者只是菜单部分。 Log
这个问题在这里已经有了答案: How can I horizontally center an element? (134 个回答) 关闭 4 年前。
我遇到了一个 CSS 问题,需要帮助。我在目录中有许多不同大小的图像,我正在动态列出它们以显示以下 View :(我仅显示两个图像作为示例) 这是我的 HTML:
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: How can I make a horizontal ListView in Android? 我已经多次使
我是一名优秀的程序员,十分优秀!