使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)

我试图根据旋转木马图像当时是否处于活动状态来更改div的显示属性。 我已经让它工作但它只有在我双击时才有效。 只需单击一下,即可显示与上一个活动图像对应的div,而不是当前活动图像。 请帮忙。

=====================================

代码如下

HTML

<div class="container-fluid" id="siteImgs">
  <div class="row col-xs-12 col-md-7">
<div id="myCarousel" class="carousel slide" data-ride="carousel">

  <!-- Carousel indicators -->

   <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" id="lg" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1" id="ma"></li>
    <li data-target="#myCarousel" data-slide-to="2" id="sz"></li>
    <li data-target="#myCarousel" data-slide-to="3"id="ti"></li>
   </ol>   

  <!-- Carousel items -->

 <div class="carousel-inner">
    <div class="item active">
        <img src="img/work/lookingGlass.png" alt="looking glass">
    </div>

    <div class="item">
        <img src="img/work/mauriceSite.png" alt="maurice site">
    </div>

    <div class="item">
        <img src="img/work/sza.png" alt="sza">
    </div>

    <div class="item">
        <img src="img/work/tina.png" alt="tina">
    </div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
 </a>
 </div>

</div>


<!--INFORMATION DIVS-->

<div class="row col-xs-12 col-md-5 lookingGlass lg">
      <h1>THE LOOKING GLASS</h1>
      <p>Lorem ipsum</p>
</div>

 <div class="row col-xs-12 col-md-5 lookingGlass ma">
      <h1>MAURICEDANIELS.COM</h1>
      <p>Lorem ipsum</p>
</div>

<div class="row col-xs-12 col-md-5 lookingGlass sz">
      <h1>SZA</h1>
      <p>Lorem ipsum</p>
</div>

<div class="row col-xs-12 col-md-5 lookingGlass ti">
      <h1>TINA D. PHOTOGRAPHY</h1>
      <p>Lorem ipsum</p>
</div>

JS / JQUERY

        $( '.ma' ).hide();
    $( '.sz' ).hide(),
    $( '.ti' ).hide();
$( ".carousel-control" ).click(function() {

if ( $( '#lg' ).hasClass( "active" ) ) {

    $( '.lg' ).show(),
    $( '.ma' ).hide();
    $( '.sz' ).hide(),
    $( '.ti' ).hide();

}

if ( $( '#ma' ).hasClass( "active" ) ) {

    $( '.ma' ).show(),
    $( '.lg' ).hide();
    $( '.sz' ).hide(),
    $( '.ti' ).hide();

}

if ( $( '#sz' ).hasClass( "active" ) ) {

    $( '.sz' ).show(),
    $( '.lg' ).hide();
    $( '.ma' ).hide(),
    $( '.ti' ).hide();

}

if ( $( '#ti' ).hasClass( "active" ) ) {

    $( '.ti' ).show(),
    $( '.lg' ).hide();
    $( '.sz' ).hide(),
    $( '.ma' ).hide();

}

});

完整示例HERE


I am trying to change the display property of a div based on if the carousel image is active at the time. I have gotten it to work but it only works when i doubleclick. With a single click it displays the div corresponding to the previous active image instead of the current one. Please HELP.

=====================================

CODE BELOW

HTML

<div class="container-fluid" id="siteImgs">
  <div class="row col-xs-12 col-md-7">
<div id="myCarousel" class="carousel slide" data-ride="carousel">

  <!-- Carousel indicators -->

   <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" id="lg" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1" id="ma"></li>
    <li data-target="#myCarousel" data-slide-to="2" id="sz"></li>
    <li data-target="#myCarousel" data-slide-to="3"id="ti"></li>
   </ol>   

  <!-- Carousel items -->

 <div class="carousel-inner">
    <div class="item active">
        <img src="img/work/lookingGlass.png" alt="looking glass">
    </div>

    <div class="item">
        <img src="img/work/mauriceSite.png" alt="maurice site">
    </div>

    <div class="item">
        <img src="img/work/sza.png" alt="sza">
    </div>

    <div class="item">
        <img src="img/work/tina.png" alt="tina">
    </div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
 </a>
 </div>

</div>


<!--INFORMATION DIVS-->

<div class="row col-xs-12 col-md-5 lookingGlass lg">
      <h1>THE LOOKING GLASS</h1>
      <p>Lorem ipsum</p>
</div>

 <div class="row col-xs-12 col-md-5 lookingGlass ma">
      <h1>MAURICEDANIELS.COM</h1>
      <p>Lorem ipsum</p>
</div>

<div class="row col-xs-12 col-md-5 lookingGlass sz">
      <h1>SZA</h1>
      <p>Lorem ipsum</p>
</div>

<div class="row col-xs-12 col-md-5 lookingGlass ti">
      <h1>TINA D. PHOTOGRAPHY</h1>
      <p>Lorem ipsum</p>
</div>

JS/JQUERY

        $( '.ma' ).hide();
    $( '.sz' ).hide(),
    $( '.ti' ).hide();
$( ".carousel-control" ).click(function() {

if ( $( '#lg' ).hasClass( "active" ) ) {

    $( '.lg' ).show(),
    $( '.ma' ).hide();
    $( '.sz' ).hide(),
    $( '.ti' ).hide();

}

if ( $( '#ma' ).hasClass( "active" ) ) {

    $( '.ma' ).show(),
    $( '.lg' ).hide();
    $( '.sz' ).hide(),
    $( '.ti' ).hide();

}

if ( $( '#sz' ).hasClass( "active" ) ) {

    $( '.sz' ).show(),
    $( '.lg' ).hide();
    $( '.ma' ).hide(),
    $( '.ti' ).hide();

}

if ( $( '#ti' ).hasClass( "active" ) ) {

    $( '.ti' ).show(),
    $( '.lg' ).hide();
    $( '.sz' ).hide(),
    $( '.ma' ).hide();

}

});

Full Example HERE


原文:https://stackoverflow.com/questions/27744104
2024-05-05 22:05

满意答案

使用更干净的方法的示例代码:

// not all values present, just a sample here
NSDictionary *stringsToSounds = @{@"friend":@"You're my best friend", @"hat are you doing":@"I'm talking to you", @"chips":@"chipds"};

NSDictionary *stringsToLabels = @{@"friend":@"You're my best friend", @"hat are you doing":@"I'm talking to you", @"chips":@"Ooooh. I love chips."};

for(NSString *s in stringsToSounds) {
    if([string rangeOfString:s] != NSNotFound) {
        if(stringsToLabels[s]) {
            [label setText:stringsToLabels[s]];
        }
        [self playSound:stringsToSounds[s]];
        break;
    }
}

和方法playSound看起来像:

-

    (void) playSound(NSString *) soundFileName {
        SystemSoundID SoundID;
        NSString *soundfile= [[NSBundle mainBundle] pathForResource:soundFileName ofType:@"mp3"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundfile], &SoundID );
        AudioServicesPlaySystemSound(SoundID);
        NSLog(@"sound played");
    }

Sample code using a cleaner approach:

// not all values present, just a sample here
NSDictionary *stringsToSounds = @{@"friend":@"You're my best friend", @"hat are you doing":@"I'm talking to you", @"chips":@"chipds"};

NSDictionary *stringsToLabels = @{@"friend":@"You're my best friend", @"hat are you doing":@"I'm talking to you", @"chips":@"Ooooh. I love chips."};

for(NSString *s in stringsToSounds) {
    if([string rangeOfString:s] != NSNotFound) {
        if(stringsToLabels[s]) {
            [label setText:stringsToLabels[s]];
        }
        [self playSound:stringsToSounds[s]];
        break;
    }
}

and method playSound looks like:

-

    (void) playSound(NSString *) soundFileName {
        SystemSoundID SoundID;
        NSString *soundfile= [[NSBundle mainBundle] pathForResource:soundFileName ofType:@"mp3"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundfile], &SoundID );
        AudioServicesPlaySystemSound(SoundID);
        NSLog(@"sound played");
    }

相关问答

更多

NS 是什么意思

NS,全名NINTENDO SWITCH,是任天堂游戏公司于2017年3月首发的旗舰产品,主机采用家用机掌机一体化设计。新机不锁区,支持1920*1080电视输出和1280*720掌上输出。港版NS于2017年3月3日发售,台版NS于12月1日发售。 这是前社长岩田聪最后一部参与开发的硬件产品,该产品将成为未来任天堂娱乐事业蓝图的中心。NS首秀获得强烈反响,预告片YouTube首日播放量超一千万回,一度登顶YouTube播放榜首,风头压过美国大选。

无法忽略带有NS标志的mod_rewrite内部重定向(Unable to ignore mod_rewrite internal redirects with NS flag)

有几个解决方法,每个都有其优点和缺点。 作为免责声明,我只在.htaccess上下文中测试过它们。 解决方法1.检查空的REDIRECT_STATUS 添加RewriteCond检查以查看%{ENV:REDIRECT_STATUS}是否为空。 如果它是空的,那么当前请求不是内部重定向。 优点 确定内部重定向的最直接方式。 缺点 缺少文档。 自定义错误响应页面简要提到了这个变量: REDIRECT_环境变量是根据重定向之前存在的环境变量创建的。 它们被重命名为REDIRECT_前缀,即HTTP_US...

是什么导致Firefox中的NS_ERROR_STORAGE_CONSTRAINT?(What causes NS_ERROR_STORAGE_CONSTRAINT in Firefox?)

正如另一个答案所说,您的Firefox配置文件已损坏。 这是事实,但您不必放弃您的个人资料。 您必须在磁盘上找到您的配置文件并删除该配置文件中的webappsstore.sqlite 。 这将清除您保存的所有站点存储空间。 为了避免将来发生这种情况,请确保不要在Nightly / Developer Edition和稳定版本的Firefox之间混合使用相同的配置文件。 修复此问题的修补程序刚刚登陆,应该很快就可以使用。 Bugzilla Bug网址: https ://bugzilla.mozil...

NS前缀是什么意思?(What does the NS prefix mean?)

这是来自NeXTSTEP的遗产。 It's from the NeXTSTEP heritage.

Azure VM DNS - 指定为“NS”和“A”记录的内容(Azure VM DNS - What to specify as 'NS' and 'A' record)

您需要为Azure虚拟机配置域所需的一切包括CNAME / A记录差异以及您需要在域名注册商网站上放置什么。 我添加Cloud Service链接的原因是,经典模式下的虚拟机(如果您创建了该VM)驻留在名为Cloud Service的特定实体中。 如果您创建了新的Azure VM,则可以使用Azure DNS服务或该方法。 因此,CNAME基本上是azure域的别名,您可能会看到第一个域。 使用A,域将映射到资源的IP地址而不是域。 选择取决于您的方案。 最简单的方法是配置CNAME,因为如果您配...

如何找出NS Log的来源是什么?(How to find out what the source of an NS Log is? [closed])

使用更干净的方法的示例代码: // not all values present, just a sample here NSDictionary *stringsToSounds = @{@"friend":@"You're my best friend", @"hat are you doing":@"I'm talking to you", @"chips":@"chipds"}; NSDictionary *stringsToLabels = @{@"friend":@"You're m...

什么是noir.server / start选项:ns for?(what is noir.server/start option :ns for?)

在Noir源代码中查看此文件 。 这提供了一个处理异常的中间件 - wrap-exceptions和此文件中的代码使用:ns选项来解析异常并在具有以下内容的映射对象中获取堆栈跟踪数据:ns键。 Check out this file in Noir source code. This provides a middle ware to handle exceptions - wrap-exceptions and the code in this file uses :ns option to p...

ns-3源代码(ns-3 source code)

下面评论的源代码。 获取可以创建udp套接字的工厂类的唯一ID TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); 实际上在节点“sinkNode”上创建一个udp套接字(无论是什么) Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (sinkNode), tid); 将我们刚刚创建的套接字绑定到“any”ipv4地址 InetSocketAddress local = ...

安装时出现NS3错误(NS3 error while installing)

我按照这个教程,它的工作: https : //www.youtube.com/watch?v = 1N3CMrfxbG4 问题可能与先决条件有关。 我安装了它们,就像它在视频中提到的一样: sudo apt-get install gcc g++ python python-dev mercurial bzr gdb valgrind gsl-bin libgsl0-dev libgsl0ldbl flex bison tcpdump sqlite sqlite3 libsqlite3-dev ...

当使用jquery在不同的ns中存在相同的元素时,xml解析中的问题(problems in xml parsing when the same element exists in different ns, using jquery)

使用find('[nodeName="title"]').text()而不是find("\\:title, title").text() 但这适用于jquery 1.6,我想用jquery 1.7.1实现相同的功能 Used find('[nodeName="title"]').text() instead of find("\\:title, title").text() But this works with jquery 1.6, i want to achieve the same wit...

相关文章

更多

Solr4:Tomcat7与Solr之多核配置(Multiple Cores)

1. 背景 多核,官方说法,让你只用一个Solr实例,实现多配置多索引的功能,为不同的应用保留不同的 ...

用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空

各位大虾晚上好,我有个问题想请教你们,我想美化html的file外观,但貌似现在还不能用css直接设计 ...

微信公众号接口添加菜单时错误(errcode":40017 invalid button type)

POST提交时总是报错: {&quot;errcode&quot;:40017,&quot;errms ...

请问一个jQuery的问题,谢谢

$(document).ready(function(){ //必须通过class属性获取jQuer ...

【原创】小白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连载五(给按钮加图标)

在范例5-4所使用的导航栏中,已经为按钮加入了图标的样式,但是当时并没有介绍按钮的图标究竟是怎么一回事 ...

Android按钮根据文本框设置状态

现在有一个需求其实挺简单的,就是按钮根据文本框里的信息设置禁用或者可用的状态,即如果文本框(TextV ...

Hadoop配置多个硬盘

在Hadoop的文档里明确提出了不需要使用RAID(见http://wiki.apache.org/h ...

在列表li里两个浮动div兼容IE6问题

本来一个很简单功能,却难以兼容IE6, &lt;ul class=&quot;ulDiv&quot ...

Linux Shell Scripting Cookbook(Linux Shell脚本攻略_英文版.pdf)

Linux Shell Scripting Cookbook的内容摘要:中文名:Linux Shell ...

Hadoop下运行多个SecondaryNameNode的配置

光从字面上来理解,很容易让一些初学者先入为主的认为:SecondaryNameNode(snn)就是N ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本