点击外部链接时打开第一个手风琴。

huangapple go评论61阅读模式
英文:

On click external link open first accordion

问题

I am trying to open its first accordion on external Link click. 我试图在点击外部链接时打开第一个手风琴。

英文:

I have created two external links and two section containing accordion in each. When I click on Link it scroll to its particular section. I am trying to open its first accordion on Link click.

https://jsfiddle.net/adampavlov/4s7dc09b/13/

$(document).ready(function(){
// Add smooth scrolling to all links
$(".explore-card a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});

I am trying to open its first accordion on external Link click.

答案1

得分: 0

将这些属性添加到第一个链接中将实现此效果:

data-toggle="collapse" data-target="#a1"

添加后它将如下所示:

<a href="#Segment1" class="explore-link" data-toggle="collapse" data-target="#a1">

https://jsfiddle.net/r1vd3jgp/

英文:

Adding these attributes to the first link will do it:

data-toggle=&quot;collapse&quot; data-target=&quot;#a1&quot;

After adding it will look like this:

&lt;a href=&quot;#Segment1&quot; class=&quot;explore-link&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#a1&quot;&gt;

https://jsfiddle.net/r1vd3jgp/

huangapple
  • 本文由 发表于 2023年7月13日 14:58:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676687.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定