英文:
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="collapse" data-target="#a1"
After adding it will look like this:
<a href="#Segment1" class="explore-link" data-toggle="collapse" data-target="#a1">
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论