- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经构建了一个旋转木马,但我希望当最后一个/第一个项目在视口(viewport)中时禁用按钮,即当最后一个项目可见时,然后禁用“下一步”按钮。我正在使用 unbind('click')
但它不起作用。
请指路。
JS:
var MYPROJECT = {
CONTROL: '.controls',
SLIDELIST: '.slide-wrapper ul',
init: function(){
this.projectCarousel();
},
projectCarousel: function(){
var self = this,
jqs_slideList = $(self.SLIDELIST),
slide = jqs_slideList.find('.slide'),
slideWidth = jqs_slideList.find('.slide').outerWidth(true),
firstSlidePos = slide.first().position().left,
lastSlidePos = slide.last().position(),
count = 0;
$(this.CONTROL).on('click', 'a', function (e) {
var thisElm = $(this);
e.preventDefault();
if (thisElm.hasClass('prev')) {/* if prev button is clicked */
jqs_slideList.animate({ marginLeft: '+=' + slideWidth + 'px' });
} else if (thisElm.hasClass('next')) {/* if next button is clicked */
jqs_slideList.animate({ marginLeft: '-=' + slideWidth + 'px' });
count++;
if (count === (slide.length - 1)) {
// disable button
thisElm.unbind('click').css({ /* this should be in css class */
opacity: 0.5,
cursor: 'default'
});
}
}
});
}
};
MYPROJECT.init();
HTML:
<div class="slideshow">
<div class="controls">
<a href="#" class="prev">-</a>
<a href="#" class="next">+</a>
</div>
<div class="slide-wrapper">
<ul>
<li class="slide">
<article>
<h3>Some title here (nav 1)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
<li class="slide">
<article>
<h3>Some title here (nav 2)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
</ul>
</div>
</div>
CSS:
.slideshow {
margin: 45px auto 0;
width: 318px;
}
.slideshow .slide-wrapper {
width:325px;
padding: 10px;
overflow: hidden;
}
.slideshow ul {
width: 696px;
}
.slideshow .slide {
float: left;
margin-right: 30px;
}
.slideshow .slide article {
background: #fff;
bottom: 0px;
box-shadow: -2px -1px 8px #bbb;
padding: 10px;
width: 298px;
z-index: 5;
}
.controls {
position: relative;
top: 150px;
}
.controls a {
color: #fff;
display: block;
font-size: 36px;
font-weight: bold;
height: 65px;
position: absolute;
text-indent: -9999px;
width: 65px;
}
.controls .prev {
left: -115px;
}
.controls .next {
right: -115px;
}
非常感谢
最佳答案
我强烈建议您使用其他方法来检查您在轮播中的位置。例如,您可以使用 .index
而不是从您的列表中。
禁用按钮的最佳方法是检查当前幻灯片索引,并向控件添加一个禁用的类,并仅根据需要设置动画
$(".slide").index() > 0
$(".slide").index() < $(".slide-wrapper ul").index() < $(".slide").index()
这是一个 JSFiddle example我为你做的。还有一个 how to create your own plugin在您的项目中考虑这一点可能会很好。只是给你一个正确的方向,祝你好运!
这是代码
(function( $ ) {
$.fn.projectCarousel = function(){
var $slides = $(".slide", this),
$current_slide = $(".slide:first-child", this),
$prev = $(".controls a.prev", this),
$next = $(".controls a.next", this);
if($current_slide.index() <= 0) $prev.addClass("disabled");
$prev.click(function(e){
e.preventDefault();
if($current_slide.index() > 0){
if($prev.hasClass("disabled")) $prev.removeClass("disabled");
$(".slide-wrapper ul").animate({ marginLeft: '+=' + $current_slide.outerWidth(true)+ 'px' });
$current_slide = $current_slide.prev();
}
if($current_slide.index() <= 0){
//disable previous
$prev.addClass("disabled");
$next.removeClass("disabled");
}
});
$next.click(function(e){
e.preventDefault();
if($current_slide.index() < $slides.index()){
if($next.hasClass("disabled")) $next.removeClass("disabled");
$(".slide-wrapper ul").animate({ marginLeft: '-=' + $current_slide.outerWidth(true)+ 'px' });
$current_slide = $current_slide.next();
}
if($current_slide.index() >= $slides.index()){
//disable next
$next.addClass("disabled");
$prev.removeClass("disabled");
}
});
}
})( jQuery );
$(".slideshow").projectCarousel();
另一种方法是将每个幻灯片元素存储在一个数组中。这种方法非常有效和可靠。这种方法的主要缺点是占用大量内存,但除非您有大量幻灯片,否则应该不是问题。这也非常有用,因为您可以决定要跳到哪张幻灯片。
一个基于数组的轮播示例可以像 this JSFiddle 中那样完成.
基本上,所有动画都包含在一个函数中 _to_slide(index)
这需要一个参数:“我应该为哪一帧制作动画?”。由于数组是基于数字的,因此更易于管理和控制。
这是代码(包括html和css,改变了一些以容纳更多功能)
Javascript
(function( $ ) {
$.fn.projectCarousel = function(){
var $slides = $(".slide", this),
$current_slide = $(".slide:first-child", this),
$prev = $(".controls a.prev", this),
$next = $(".controls a.next", this);
if($current_slide.index() <= 0) $prev.addClass("disabled");
$prev.click(function(e){
e.preventDefault();
if($current_slide.index() > 0){
if($prev.hasClass("disabled")) $prev.removeClass("disabled");
$(".slide-wrapper ul").animate({ marginLeft: '+=' + $current_slide.outerWidth(true)+ 'px' });
$current_slide = $current_slide.prev();
}
if($current_slide.index() <= 0){
//disable previous
$prev.addClass("disabled");
$next.removeClass("disabled");
}
});
$next.click(function(e){
e.preventDefault();
if($current_slide.index() < $slides.index()){
if($next.hasClass("disabled")) $next.removeClass("disabled");
$(".slide-wrapper ul").animate({ marginLeft: '-=' + $current_slide.outerWidth(true)+ 'px' });
$current_slide = $current_slide.next();
}
if($current_slide.index() >= $slides.index()){
//disable next
$next.addClass("disabled");
$prev.removeClass("disabled");
}
});
}
})( jQuery );
$(".slideshow").projectCarousel();
HTML
<div class="slideshow">
<div class="controls">
<a href="#" class="start"><-</a>
<a href="#" class="prev">-</a>
<input class='select' type='text' value='1' />
<a href="#" class="next">+</a>
<a href="#" class="end">-></a>
</div>
<div class="slide-wrapper">
<ul>
<li class="slide">
<article>
<h3>Some title here (nav 1)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
<li class="slide">
<article>
<h3>Some title here (nav 2)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
<li class="slide">
<article>
<h3>Some title here (nav 3)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
<li class="slide">
<article>
<h3>Some title here (nav 4)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
<li class="slide">
<article>
<h3>Some title here (nav 5)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
<li class="slide">
<article>
<h3>Some title here (nav 6)</h3>
<p>Over the past few years, mobile web usage has considerably increased.</p>
</article>
</li>
</ul>
</div>
</div>
CSS
.slideshow {
margin: 45px auto 0;
width: 318px;
}
.slideshow .slide-wrapper {
width:325px;
padding: 10px;
overflow: hidden;
}
.slideshow ul {
width: 2088px;
}
.slideshow .slide {
float: left;
margin-right: 30px;
}
.slideshow .slide article {
background: #fff;
bottom: 0px;
box-shadow: -2px -1px 8px #bbb;
padding: 10px;
width: 298px;
z-index: 5;
}
.controls {
position: relative;
display: block;
overflow: auto;
clear: both;
text-align: center;
}
.controls a {
color: #fff;
display: block;
font-weight: bold;
height: 18px;
width: 18px;
background-color: #000;
text-decoration: none;
text-align: center;
line-height: 16px;
display: inline-block;
}
input.select{
width: 35px;
text-align: center;
}
a.disabled{
cursor: default;
background-color: #d6d6d6;
}
如果你对这个主题背后的一些理论感兴趣,你可以继续阅读它们
linked lists对比vectors对比deques .
尽管大部分链接都指向 C++ 库,但该理论适用于所有编程语言。
关于javascript - 当最后一项在 javascript 的轮播中可见时如何禁用链接/按钮/等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9467392/
在gdb中获取此消息。我知道它不是错误或任何东西。我也做了分页,所以那不是问题。 有什么办法可以抑制此消息? 最佳答案 我很好奇看到这个问题没有得到解决... 我获得了GDB manual,它说(部分
好吧,这很烦人,而且可能很简单。我想用禁用的复选框启动我的网页,并在选择列表框中的特定行后启用这些框。所以我把它放在 onload 方法中 onload = function () { for
看来我需要以某种方式在我的 php 页面上禁用 IPv6,但我不确定该怎么做。我想我必须在我的 INI 文件中的某处添加 --disable-ipv6 ……虽然这看起来不像正确的语法。 我正在尝试解决
我有这两个代码: 第一个是禁用复制粘贴的宏: Sub Desable_Copy() Dim oCtrl As Office.CommandBarControl For Each oCt
在下面的代码中,我想, 如果我选择/单击“患者类型”按钮。它们在菜单“xmenumain”“儿科心电图”项中应该被禁用(它应该列在菜单列表中,但颜色为淡灰色)。我如何实现它? void MyMenu:
我目前在 Coordinator 布局中有一个底部导航栏,我向其添加了 HideBottomViewOnScrollBehaviour。有些屏幕需要隐藏导航栏,我可以通过从 BottomNavigat
我需要一些关于 jquery if 条件的帮助。我已经搜索和测试了几个小时,任何帮助都会很棒!我得到这个 HTML 代码: Value: No Match Test Test 2 Test 3
我正在开发 Delphi -7 中的自定义组件我有一些published特性 private { Private declarations } FFolderzip ,Fi
尝试学习菜单处理的基础知识。我的测试应用程序的菜单栏有 3 个菜单——即“TestApp”、“File”和“Help”。我发现我可以完全删除这些菜单,只需调用 say: NSMenu* rootMen
我以编程方式创建一个 NSMenuItem,但它被禁用。如果我重写 validateMenuItem: 方法并为所有项目返回 YES,则菜单项工作正常。 当我告诉菜单 autoEnableItems
我的 Web 表单中有一个 asp 按钮 (runat="server") 进入更新面板。 当我点击这个按钮时,它会执行一些操作。 Private Sub ButtonDoI
我目前正在为 video.js 构建一个插件,它可以在某些断点处将覆盖层呈现在屏幕上。但是,在不启动视频的情况下,我无法单击任何叠加层。我认为我需要禁用播放器上的点击播放功能。 我应该如何禁用/启用
设置剑道网格 selectable: "row", navigatable: true, 允许选择列标题单元格并通过键盘切换其排序状态。如何完全禁用使用键盘选择列标题单元格的功能? 最
我不想卸载code rush。我只是想在不需要的时候有机会将其关闭。 这可能吗? (快速版本)... 最佳答案 首先您应该打开“DevExpress”菜单。默认情况下,它在 CodeRush Xpre
设置: 我正在使用 TinyMCE 的 Angular 包装器来允许我的用户构建自己的电子邮件模板。这些电子邮件会发送给每个用户组织内的多个人员。我创建了自定义工具栏按钮来插入小文本 block [[
我希望下拉菜单在悬停时打开,前提是窗口大于 767 像素。我试图在页面加载和窗口调整大小时调用一个函数,并使用宽度大小条件。 enableHover() 函数仅适用于页面加载,不适用于窗口调整大小。
由于我遇到了一些问题,我正在 .NET Framework 4 中尝试连接池。使用 SQL Profiler,我可以看到每次从连接池中获取连接时,都会执行存储过程 sp_reset_connectio
我避免在我的 swift 代码中收到警告。然而,当谈到 Storyboard要求时,这对我来说有点困难。 所以现在我只想禁用 xcode 显示有关 Storyboard问题的警告。 我尝试了以下方法但
我不是 JavaScript 专家,我目前正在尝试为表单创建一个函数,该函数根据上一页上选择的数字重复相同的字段。 表单字段可能有 1 到 10 行,每行都有一个单选按钮选择,可启用/禁用每一行。 目
我正在尝试使用 CPU2006 运行各种基准测试,以查看各种优化在 gcc 速度方面的作用。我熟悉 -O1、-O2 和 -O3,但听说 -msse 是一个不错的优化。 -msse 到底是什么?我还看到
我是一名优秀的程序员,十分优秀!