html - JQuery, scroll to element in different divs -
i know if there anyway in jquery scroll elements inside different divs. example, if go example.com/programme#event-2, div on left should scroll element id="event-2", , div on right should scroll element id="event-2". here's html:
<div id="events"> <div id="event-list"> <div class="content"> <h2>vendredi 17 octobre</h2> <ul id="event-1" class="event-title"> list items </ul> <h2>vendredi 21 octobre</h2> <ul id="event-2" class="event-title"> list-items </ul> </div> </div> <div id="event-details"> <div class="content"> <section id="event-1" class="details"> stuff </section> <section id="event-2" class="details"> stuff </section> </div> </div> </div>
you can have @ codepen, visualize problem. thank you!
here link example : codepen
first of important
id can use once , u use class #event-1 etc
second create button first columns, red "scroll"
$(function(){ var thisoffset = $("#event-5").offset().top; // element top offset $(".scroll").on("click", function(e){ console.log("scroll") $("#event-list .content").animate({ //scroll specific offset on click scrolltop: thisoffset }, 1000) e.preventdefault(); }); });
Comments
Post a Comment