You can use jQuery UI accordion and get the items using REST API as shown below:
<html>
<head>
<script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.js" type="text/javascript"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
GetItems();
});
function GetItems(){
var siteURL = _spPageContextInfo.webServerRelativeUrl;
$.ajax({
url: siteURL + "/_api/web/lists/GetByTitle('Loyalty%20Rewards')/items", //change the list name
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
},
success: function(data) {
if (data.d.results.length > 0)
{
$('#accordion').append(GenerateAccordionFromJson(data.d.results));
$( "#accordion" ).accordion();
}
else{
$('#accordion').append("<span>No Records Found.</span>");
}
},
error: function(error){
alert(JSON.stringify(error));
}
});
}
function GenerateAccordionFromJson(objArray)
{
var accordionContent = "";
for (var i = 0; i < objArray.length; i++)
{
accordionContent += '<h3>' + objArray[i].Title + '</h3>';
//change the column name
accordionContent += '<div><p>' + objArray[i].Description + '</p></div>'; //change the column name
}
return accordionContent;
}
</script>
</head>
<body>
<div id="accordion">
</div>
</body>
</html>
Above code is tested and works well, all you need to is change the list title and the column name from where you want to show the data.
Reference: jQuery UI Accordion