Reveal / Hide Information Panel Using JQuery -
i trying display overlay panel additional information on top of image when button clicked. html looks below , there can unlimited amount of these sections.
<div class="half"> <img src="https://upload.wikimedia.org/wikipedia/commons/c/c0/biyariver.jpg" alt=""> <div class="information""> <p>left image overlay information</p> </div> <!-- .information --> <div class="info-icon"></div><!-- .info-icon --> </div> <!-- .half -->
the '.information' overlay set display: none in css , had jquery code below:
$(".info-icon").click(function () { if( $(".information").is(":hidden") ) { $(this).css("background","url(https://cdn0.iconfinder.com/data/icons/very-basic-android-l-lollipop-icon-pack/24/close-128.png"); $(".information").css("display","block"); } else { $(this).css("background","url(https://cdn2.iconfinder.com/data/icons/app-types-in-grey/128/info_512pxgrey.png"); $(".information").css("display","none"); } });
however affected of panels @ once , not after.
so i've got code below closer want it's not working expected. can reveal panel each section not close until last section , shows , reveals expected.
$(".info-icon").click(function () { if( $(".information").is(":hidden") ) { $(this).css("background","url(http://butterscotch.wecreatedev.co.uk/wp-content/themes/butterscotch-child/img/close.svg"); $(this).closest('.half').find('.information').css("display","block"); } else { $(this).css("background","url(http://butterscotch.wecreatedev.co.uk/wp-content/themes/butterscotch-child/img/information.svg"); $(this).closest('.half').find('.information').css("display","none"); } });
js fiddle has been created demo issue:
https://jsfiddle.net/g83lbodu/4/
all time , appreciated this.
you need update if
condition satisfy closest .information
div. also, don't need set css directly, should able use .hide()
, .show()
so new code should read follows:
$(".info-icon").click(function () { if( $(this).closest('.half').find('.information').is(":hidden") ) { $(this).css("background","url(http://butterscotch.wecreatedev.co.uk/wp-content/themes/butterscotch-child/img/close.svg"); $(this).closest('.half').find('.information').show(); } else { $(this).css("background","url(http://butterscotch.wecreatedev.co.uk/wp-content/themes/butterscotch-child/img/information.svg"); $(this).closest('.half').find('.information').hide(); } });
updated fiddle: https://jsfiddle.net/g83lbodu/7/
Comments
Post a Comment