- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是我第一次尝试创建基于按钮的 slider 。
每张幻灯片分为两部分,左边是一张图片,右边是一些文字。切换幻灯片时,就在幻灯片加载之前出现意外反弹,我似乎无法理解为什么会发生这种情况。
有什么好的方法可以实现同一张幻灯片吗?
代码如下:
$( function() {
imw_slider();
})
function imw_slider() {
var button = $( '.slide-button' );
button.click( function() {
button.css( 'background-color', '#fff' );
$(this).css( 'background-color', '#eee' );
var index = $(this).index();
var image = $(this).parent().prev();
image.children('.slide:not(:nth-child('+(index+1)+'))').fadeOut( function() {
image.children('.slide:nth-child('+(index+1)+')').fadeIn();
});
});
}
.image-box > .images {
text-align: center;
}
.image-box > .images > .slide:nth-child(1) {
display: block;
}
.image-box .slide.slide-2 {
position: relative;
max-width: 80rem;
margin: 0 auto;
}
.image-box > .images > .slide {
display: none;
}
.image-box > .images > .slide:after {
display: block;
content: '';
clear: both;
}
.image-box .slide.slide-2 > div {
width: 50%;
float: left;
}
.image-box .buttons {
display: table;
margin: 0 auto;
margin-top: 15px;
border: 1px solid #ccc;
border-radius: 4px;
overflow: hidden;
}
.image-box .buttons .slide-button {
display: table-cell;
cursor: pointer;
padding: 2px 10px;
border-right: 1px solid #ccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image-box my4">
<div class="images">
<div class="slide slide-2">
<div><img src="http://test.storeapps.org/wp-content/uploads/2016/11/Putler-Web-customers-sample.png" alt="" /></div>
<div>
<div class="text">
<h2>This is the text for slide 1</h2></div>
</div>
</div>
<div class="slide slide-2">
<div><img src="http://test.storeapps.org/wp-content/uploads/2016/11/Putler-Web-customers-sample.png" alt="" /></div>
<div>
<div class="text">
<h2>This is the text for slide 2</h2></div>
</div>
</div>
<div class="slide slide-2">
<div><img src="http://test.storeapps.org/wp-content/uploads/2016/11/Putler-Web-customers-sample.png" alt="" /></div>
<div>
<div class="text">
<h2>This is the text for slide 3</h2></div>
</div>
</div>
</div>
<div class="buttons"><span class="slide-button">button-1</span><span class="slide-button">button-2</span><span class="slide-button">button-3</span></div>
</div>
最佳答案
不是淡出除了已经淡入的幻灯片之外的所有幻灯片,您可以先隐藏它们然后淡入当前使用此幻灯片:
image.children('.slide:not(:nth-child('+(index+1)+'))').hide();
image.children('.slide:nth-child('+(index+1)+')').fadeIn();
或者更好的是,您可以保存最后一张事件幻灯片并淡出并淡入当前幻灯片:
if (prev_slide) {
prev_slide.fadeOut(function() {
prev_slide = image.children('.slide:nth-child(' + (index + 1) + ')');
prev_slide.fadeIn();
});
} else {
prev_slide = image.children('.slide:nth-child(' + (index + 1) + ')');
prev_slide.fadeIn();
}
请看下面的演示:
$(function() {
imw_slider();
})
var prev_slide = null;
function imw_slider() {
var button = $('.slide-button');
button.click(function() {
button.css('background-color', '#fff');
$(this).css('background-color', '#eee');
var index = $(this).index();
var image = $(this).parent().prev();
if (prev_slide) {
prev_slide.fadeOut(function() {
prev_slide = image.children('.slide:nth-child(' + (index + 1) + ')');
prev_slide.fadeIn();
});
} else {
prev_slide = image.children('.slide:nth-child(' + (index + 1) + ')');
prev_slide.fadeIn();
}
});
}
.image-box > .images {
text-align: center;
}
.image-box > .images > .slide:nth-child(1) {
display: block;
}
.image-box .slide.slide-2 {
position: relative;
max-width: 80rem;
margin: 0 auto;
}
.image-box > .images > .slide {
display: none;
}
.image-box > .images > .slide:after {
display: block;
content: '';
clear: both;
}
.image-box .slide.slide-2 > div {
width: 50%;
float: left;
}
.image-box .buttons {
display: table;
margin: 0 auto;
margin-top: 15px;
border: 1px solid #ccc;
border-radius: 4px;
overflow: hidden;
}
.image-box .buttons .slide-button {
display: table-cell;
cursor: pointer;
padding: 2px 10px;
border-right: 1px solid #ccc;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image-box my4">
<div class="images">
<div class="slide slide-2">
<div>
<img src="http://test.storeapps.org/wp-content/uploads/2016/11/Putler-Web-customers-sample.png" alt="" />
</div>
<div>
<div class="text">
<h2>This is the text for slide 1</h2>
</div>
</div>
</div>
<div class="slide slide-2">
<div>
<img src="http://test.storeapps.org/wp-content/uploads/2016/11/Putler-Web-customers-sample.png" alt="" />
</div>
<div>
<div class="text">
<h2>This is the text for slide 2</h2>
</div>
</div>
</div>
<div class="slide slide-2">
<div>
<img src="http://test.storeapps.org/wp-content/uploads/2016/11/Putler-Web-customers-sample.png" alt="" />
</div>
<div>
<div class="text">
<h2>This is the text for slide 3</h2>
</div>
</div>
</div>
</div>
<div class="buttons"><span class="slide-button">button-1</span><span class="slide-button">button-2</span><span class="slide-button">button-3</span>
</div>
</div>
关于javascript - 为什么 jQuery 幻灯片在选择时弹跳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41529744/
我是一个 JS 菜鸟。我正在进入浏览器游戏编程,并想制作一个球掉落和弹跳的快速示例以供学习。由于某种原因,当我创建 jsfiddle 时,我的代码实际上不起作用,我的 div id="ball"的 o
我正在努力寻找为此目的的插件/插件,它是我项目的关键部分,我忽略了它,现在它咬了我。 我需要 jQuery 弹跳的变体,它使 div 无限期地围绕父 div/包装器弹跳。 实际上,我将拥有一个屏幕,用
我的 Nib 底部有一个 UIView。我希望它的高度能够增长,但让它看起来好像它没有移动位置,只是在增长。然后将高度缩小回原来的高度,除了高度之外不进行任何移动。不幸的是,它在 y 位置上反弹。它会
我做错了什么?我的技能栏正在跳舞。加载后我想修复它们。 在这里检查我的笔:http://codepen.io/anon/pen/KdEeWW $(window).scroll(function() {
我有一个有 2 列的表格,其中一列具有设定的宽度,第二列占据页面的其余部分。 在第一列中,我有另一个包含 2 个 tr 元素的表(这是由 asp 生成的) 如此处所示的表格:http://jsfidd
我正在使用 jQuery 构建基于标准 ul>li 结构的下拉导航。 一切都运行良好,但是,当我到达三元级别项目时,slideToggle 函数会导致“反弹”并且永远不会显示子 UL 由于有相当多的代
大家好,谢谢大家的帮助, 我想做的事情相当简单,我想显示一个跟随我的弹跳/反射 Raycast 的线渲染器。 这是我目前所拥有的。 private LineRenderer lr; public i
我试图对齐中间圆圈中的文本并让它们在圆圈悬停时弹跳(即文本) 这里是: http://jsfiddle.net/cJ3se/ 希望有人能帮忙 丹佛 最佳答案 将元素中的单行文本垂直居中的最简单方法是将
这很难解释,我来试一试。 我目前有一个从右向左无休止地滑动的图像背景,就像传送带一样。图像用完时会重复。 我试图让图像/动画在重复之前反弹(反向)。所以图像慢慢地向一个方向滑动,然后慢慢地向另一个方向
我想知道为什么我的弹跳动画在 JSFiddle 中不起作用但在我的开发网站上工作。请检查这个有什么问题。在我的开发站点中,箭头会弹跳但不会像我的 CSS 类中所说的那样旋转。 .active.ongo
我正在使用Pymunk模拟安装在细长腿顶部枢轴上的盒子的物理特性,该腿固定在地面上。连接盒子和腿的枢轴是 PivotJoint 和 SimpleMotor 的组合,模拟原始伺服系统,用户可以打开和关闭
我正在开发一个带有 ScrollView 的应用程序。不是很明显有更多内容,并且没有滚动指示器( ScrollView 被分页)。 所以,为了给用户一个“嘿,这里有东西……”,我想让 ScrollVi
我的应用程序中有启用了垂直弹跳的 UIScrollView。我需要屏幕底部的弹跳,但没有在屏幕顶部启用。 我不知道如何用以下方法检测 ScrollView : (void)scrollViewWi
我的网站有问题,我在其中使用带有 jQuery UI 的 jQuery,在登录框上创建弹跳效果。 但是,我对带有登录框的 div 有问题,因为它在屏幕左侧弹跳,当它应该在中间弹跳时,它在完成弹跳后
当网页内容大于视口(viewport)时,我正在尝试实现一种解决方案,以防止 iOS 版 Safari 中的 iOS 反弹效果。 我正在处理的页面在结构上非常具体,与此页面非常相似 http://ne
第一次在这里发帖,如有任何标记问题请见谅。写帖子用SOF框架不习惯。 我试图让一些社交图标在悬停时在我的网站上跳动。我从 jQuery UI 抓取代码进行测试并进行了一些小的编辑,但是我遇到了页面上可
我有一个 UIScrollView,我想在滚动时弹跳,但目前它能够弹跳,尽管内容大小与框架相同。如果内容大小和框架大小相同,如何阻止它弹跳?有没有比重写 setContentSize 和 setFra
我的网页最右侧有一个 div (RightSide),它位于另一个 div (TopBanner) 的正下方。即使用户向下滚动,TopBanner div 也会保持其在屏幕顶部的准确位置。正是我想要的
我有一个带分页的水平 UIScrollView。有两个按钮。一个向左滚动 scrollView,另一个向右滚动。 左边的代码: - (IBAction)goLeftAction:(id)sender
我正在尝试创建自定义垂直 UIScrollView,它可以处理具有不同页面高度的多个页面。 假设: 页面高度等于或大于屏幕高度 如果页面高于屏幕高度,它会像往常一样滚动 UIScrollView –
我是一名优秀的程序员,十分优秀!