我试图通过单击按钮并跳到给定元素的位置来滚动水平div。
我正在尝试这样:
<input type="button" class="hor" onmousedown="scrollDiv6('MyDiv3', Eve_25)" value=@Model.CalendarDates[i].Date />
<script>
var timer6;
function scrollDiv6(divId6, depl6) {
var scroll_container6 = document.getElementById(divId6);
var target = $(document.getElementById(depl6)).position().left;
scroll_container6.scrollTo(target);
//timer6 = setTimeout('scrollDiv6("' + divId6 + '", ' + depl6 + ')', 1);
}
</script>
<div class="scrolling-wrapper-flexbox scroller" id="MyDiv3" style="width:100%;position:relative; z-index:2;">
@for (int i = 0; i < Model.HomeEventsList.Count(); i++)
{
<div class="card2" style="width:300px;height:400px;" id="Eve_@i">
<div style="text-align:center;">
<h4 style="font-size:30px;text-align:center;" class="center-fit">@Model.HomeEventsList[i].EventName.ToString()</h4>
<div class="featuredImageBox" style="width:280px">
<img height="200" width="280" style="object-fit:cover" src="~/UserFiles/@Model.Owner/min/@Model.HomeEventsList[i].EventFeaturedImage" />
</div>
<div style="text-align:center;">
<span class="center-fit" style="text-align:center;font-size:30px;">
@Model.HomeEventsList[i].EventStart.DayOfWeek.ToString()
@Model.HomeEventsList[i].EventStart.ToString("dd MM yyyy")
</span>
</div>
<div style="text-align:center">
<span class="center-fit" style="text-align:center;font-size:30px;">
@Model.HomeEventsList[i].EventStart.ToString("HH:mm")
@Model.HomeEventsList[i].EventDuration
</span>
</div>
<h4 class="center-fit" style="text-align:center;font-size:30px;overflow-wrap: break-word;word-wrap: break-word;hyphens: auto;">@Model.HomeEventsList[i].EventDescription.ToString()</h4>
</div>
</div>
}
</div>
在按钮上单击,没有任何反应。
如何在单击按钮时滚动到给定的元素?