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

使用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 是什么意思[2023-11-27]

    NS,全名NINTENDO SWITCH,是任天堂游戏公司于2017年3月首发的旗舰产品,主机采用家用机掌机一体化设计。新机不锁区,支持1920*1080电视输出和1280*720掌上输出。港版NS于2017年3月3日发售,台版NS于12月1日发售。 这是前社长岩田聪最后一部参与开发的硬件产品,该产品将成为未来任天堂娱乐事业蓝图的中心。NS首秀获得强烈反响,预告片YouTube首日播放量超一千万回,一度登顶YouTube播放榜首,风头压过美国大选。
  • 有几个解决方法,每个都有其优点和缺点。 作为免责声明,我只在.htaccess上下文中测试过它们。 解决方法1.检查空的REDIRECT_STATUS 添加RewriteCond检查以查看%{ENV:REDIRECT_STATUS}是否为空。 如果它是空的,那么当前请求不是内部重定向。 优点 确定内部重定向的最直接方式。 缺点 缺少文档。 自定义错误响应页面简要提到了这个变量: REDIRECT_环境变量是根据重定向之前存在的环境变量创建的。 它们被重命名为REDIRECT_前缀,即HTTP_USER_AG ...
  • 正如另一个答案所说,您的Firefox配置文件已损坏。 这是事实,但您不必放弃您的个人资料。 您必须在磁盘上找到您的配置文件并删除该配置文件中的webappsstore.sqlite 。 这将清除您保存的所有站点存储空间。 为了避免将来发生这种情况,请确保不要在Nightly / Developer Edition和稳定版本的Firefox之间混合使用相同的配置文件。 修复此问题的修补程序刚刚登陆,应该很快就可以使用。 Bugzilla Bug网址: https ://bugzilla.mozilla.or ...
  • 这是来自NeXTSTEP的遗产。 It's from the NeXTSTEP heritage.
  • 您需要为Azure虚拟机配置域所需的一切包括CNAME / A记录差异以及您需要在域名注册商网站上放置什么。 我添加Cloud Service链接的原因是,经典模式下的虚拟机(如果您创建了该VM)驻留在名为Cloud Service的特定实体中。 如果您创建了新的Azure VM,则可以使用Azure DNS服务或该方法。 因此,CNAME基本上是azure域的别名,您可能会看到第一个域。 使用A,域将映射到资源的IP地址而不是域。 选择取决于您的方案。 最简单的方法是配置CNAME,因为如果您配置A,您将 ...
  • 使用更干净的方法的示例代码: // 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 bes ...
  • 在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 parse ...
  • 下面评论的源代码。 获取可以创建udp套接字的工厂类的唯一ID TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); 实际上在节点“sinkNode”上创建一个udp套接字(无论是什么) Ptr recvSink = Socket::CreateSocket (c.Get (sinkNode), tid); 将我们刚刚创建的套接字绑定到“any”ipv4地址 InetSocketAddress local = InetS ...
  • 我按照这个教程,它的工作: 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 libxm ...
  • 使用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 with jqu ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。