简体   繁体   English

同位素单击以切换-如何使用关闭按钮

[英]Isotope Click to Toggle - How to use close button

I am using the following code in my JS to toggle the size of a grid element when clicked. 我在JS中使用以下代码来在单击时切换网格元素的大小。 When a element is clicked, this toggle changes the size of the element, and displays more content. 单击元素时,此切换按钮将更改元素的大小,并显示更多内容。

Currently, the whole clicked element is clickable in order to return it to its previous state. 当前,整个clicked元素都是可单击的,以便使其恢复到之前的状态。 Is it possible to add a close 'X' button that is linked to toggling the state instead of having the whole element clickable? 是否可以添加一个链接到切换状态的关闭“ X”按钮,而不是使整个元素都可单击?

$grid.on( 'click', '.grid-item', function() {
  // change size of item by toggling gigante class
  $( this ).toggleClass('gigante').siblings().removeClass('gigante');
  $grid.isotope('layout');
});

https://codepen.io/whitinggg/pen/pLMdWB https://codepen.io/whitinggg/pen/pLMdWB

Try this: 尝试这个:

$grid.on( 'click', '.toggle', function() {
// change size of item by toggling gigante class
$(this ).closest('.grid-item').toggleClass('gigante').siblings().removeClass('gigante');
$grid.isotope('layout');
});

Change your buttons: 更改按钮:

<p><i class="toggle far fa-plus-square"></i></p>
<div class="toggle close-button"><button>X</button></div>

Here is a codepen 这是一个codepen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM