- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 jquery 新手(实际上,一般来说是网页设计/开发),我正在尝试让这个层次结构面板系统适用于网站(90% 通过移动设备访问)。我已经很接近了,但我似乎无法在网上很好地表达我的问题是什么。
这是我在 jsfiddle 上的代码 https://jsfiddle.net/o7x4r67w/1/
var main = function() {
"use strict";
// Outer next arrow click
$('.out-arrow-next').click(function() {
// transition to the next outer slide
var currentOuterSlide = $('.outer-active');
var nextOuterSlide = currentOuterSlide.next();
// reset to the beginning if we've reached the end
if (nextOuterSlide.length === 0) {
nextOuterSlide = $('.outer').first(".outer");
}
currentOuterSlide.hide(200).removeClass('outer-active');
nextOuterSlide.show(200).addClass('outer-active');
});
// Outer prev arrow click
$('.out-arrow-prev').click(function() {
// transition to the prevous outer slide
var currentOuterSlide = $('.outer-active');
var prevOuterSlide = currentOuterSlide.prev(".outer");
// reset to the end if we've reached the beginning
if (prevOuterSlide.length === 0) {
prevOuterSlide = $('.outer').last();
}
currentOuterSlide.hide(200).removeClass('outer-active');
prevOuterSlide.show(200).addClass('outer-active');
});
// Inner next arrow click
$('.in-arrow-next').click(function() {
// transition to the next inner slide
var currentinnerSlide = $('.inner-active');
var nextinnerSlide = currentinnerSlide.next();
// reset to the beginning if we've reached the end
if (nextinnerSlide.length === 0) {
nextinnerSlide = $('.inner').first(".inner");
}
currentinnerSlide.hide(200).removeClass('inner-active');
nextinnerSlide.show(200).addClass('inner-active');
});
// Inner prev arrow click
$('.in-arrow-prev').click(function() {
// transition to the previous inner slide
var currentinnerSlide = $('.inner-active');
var previnnerSlide = currentinnerSlide.prev(".inner");
// reset to the end if we've reached the beginning
if (previnnerSlide.length === 0) {
previnnerSlide = $('.inner').last();
}
currentinnerSlide.hide(200).removeClass('inner-active');
previnnerSlide.show(200).addClass('inner-active');
});
};
$(document).ready(main);
这只是一个小型项目,目的是使嵌套的轮播式设置正常工作,然后我计划将其实现到实际站点。移动版本将有滑动而不是箭头。
基本上发生的事情是外部面板切换工作正常,但假设我切换了内部“英雄”列表。点击上一个会将第二个外部类的最终内部列表设置为事件状态。点击下一步将设置正确的第一个外部面板的内部英雄,但也会将第二个设置为事件状态。这是因为我的两个内部面板都包含“内部事件”类吗?或者这是因为上一个和下一个箭头的名称相同?如果是这样的话,这是否意味着我必须为每个实例创建一个点击函数?
提前致谢!
最佳答案
您的思路是正确的,表明每个 .outer
block 中使用的 inner-active
类存在问题。然而,这很容易克服。您需要确定在内部 next 和 prev 点击处理程序中选择的元素的范围,以便,例如,不会返回页面上的所有 .inner-active
元素,而仅返回受影响的容器。
$('.in-arrow-next').click(function() {
var $container = $(this).parents('.outer');
var currentinnerSlide = $container.find('.inner-active');
var nextinnerSlide = currentinnerSlide.next();
// reset to the beginning if we've reached the end
if (nextinnerSlide.length === 0) {
nextinnerSlide = $container.find('.inner').first(".inner");
}
/* ... */
});
$('.in-arrow-next').click(function() {
var $container = $(this).parents('.outer');
var currentinnerSlide = $container.find('.inner-active');
var previnnerSlide = currentinnerSlide.prev(".inner");
// reset to the end if we've reached the beginning
if (previnnerSlide.length === 0) {
previnnerSlide = $container.find('.inner').last();
}
/* ... */
});
关于javascript - jquery .next() 和 .prev() 在同一个 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36532805/
我查阅了整个 jQuery 文档,但没有找到任何内容:是否可以搜索当前元素之前具有特定类的元素?我以为这会起作用,但事实并非如此: $(this).prev('.bar'); http://jsfid
如何避免 .prev().prev().prev() 调用?有捷径吗? 最佳答案 您可以将 .prevAll 与 eq 或 :eq 结合使用,因为 prevAll 返回一组从最接近当前元素 [0] 的
目前我正在尝试使用 Node 运行一个非常基本的待办事项列表。设置 package.json 和 server.js 后,我运行了 npm start run,但出现了一个奇怪的错误。 更新:这是基本
我有一个名为 Scores 的表: mysql> select * from Scores; +------+-------+ | Id | Score | +------+-------+ |
我对这段代码有疑问: poss = [6,9,20] for n in range(6,66): if(n%6) == 0 or (n%9) == 0 or (n%20) == 0:
我正在阅读 React 钩子(Hook)的示例。我发现他们写 setCount(count + 1) 但我通常是这样写的 setCount(prev => prev + 1) 有什么区别吗?哪一个更好
如何使用 prev() 选择前一个元素?我希望当我点击icon 1时它会删除span。 html.erb # inside a loop -- notice the loop!. icon 1
我有这个 html 代码: 1 require 'yaml' 2 require 'set' 3 4 module ActiveRecord #:nodoc: 5
如何避免双重释放或损坏 (!prev) 我有这些结构: 空设备,始终有效 static struct mixer null_mixer = { .set_device = null_set_d
I get the following error when running a c program: * Error in `./final': double free or corruption
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: jquery find closest previous sibling with class 下面给出的代
我在一个文件中有这样的代码... $d = new db(); class db { function fetchform() { global $wpdb; $con
我想在点击事件中将类添加到最近的 p: http://jsfiddle.net/d7gFf/2/ 但这无法向 p 元素添加或删除类。点击事件有什么问题。 提前致谢 最佳答案 closest()搜索祖先
我在 jQuery 中使用 prev() 时遇到问题,它没有选择正确的元素。 我的HTML结构如下: ... ... “事件”部分是#contact。我想选择上一节,跳过
首先,我使用名为listrec的结构定义了节点。因此,每个节点包含3个部分:prev(用于存储前一个节点的地址),value(用于存储值)和next(用于存储下一个节点的地址)。 #include
我正在尝试删除以下代码的最后两个中断标记实例: Link stupid font tag Someth
代码: h4 inside anchor This is a sibling paragraph of that anchor which had h4 in it
鉴于这个简单的设置 I'm spoiled I'm spoiled 当我检测到对类“uncle”的点击时,我想获取最近的前一个“.parent”的同级。我应该可以做到 $(
当我使用 $('#btn').prev().text('new string'); 单击按钮时,我成功更改了按钮值但我不知道为什么应该使用 .prev() 根据http://api.jquery.co
我正在尝试使用 jQuery 获取输入值。在我的真实代码中,我有更多的输入和按钮,因此像: .middle() 这样的代码将不起作用!我需要从 btn 向上遍历。 HTML Help Alert
我是一名优秀的程序员,十分优秀!