[英]how to go to specific slide on leftChevron click in bootstrap carousel instead of going to immediate previous slide?
[英]How to call a JS Function from View(cshtml file) for going to a specific slide in Bootstrap carousel Control?
我有以下情況:
視圖上有一個“ askaQuestion”按鈕,如下所示:
<button id="btnAskQuestion" class="btn btn-primary btn-sm" data-url="@Url.Action("SendMessage", "Messages", new { category = @note.PageName, patientId = @note.PatientId, appointmentId = Model.AppointmentId, Index = noOfForms }) ">"Ask A Question"</button>
基本上單擊此按鈕(此按鈕僅在輪播的特定幻燈片上可見,而在所有幻燈片上不可見),我將用戶重定向到其他Controller / Action方法,並且再次由於該頁面上用戶交互的緣故他將返回同一頁面。
現在,我的意圖是使用戶位於單擊“ askaButton”的同一輪滑動幻燈片上,而不是強迫他從第一張幻燈片再次開始。為此,我保留了最后一個變量,即Index; 但是我不僅不能讓他落在同一張幻燈片上。
我嘗試了幾種差異方法:
goToSlide()
。 在加載視圖時,正試圖使該特定幻燈片的class =“ active”,如下所示。 在ViewBag.index
,我ViewBag.index
了最后一張幻燈片的編號,即單擊了askAQuestion
按鈕的位置。
<ol class="carousel-indicators"> @for (int slideCount = 0; slideCount < @formCount; slideCount++) { if (@formCount == 1) { <li data-target="#divFormCarousel" data-slide-to="@slideCount" class="active"></li> } else { if (ViewBag.index == 0 || ViewBag.index == null) { <li data-target="#divFormCarousel" data-slide-to="@slideCount"></li> } if (ViewBag.index != 0 && ViewBag.index != null && slideCount == ViewBag.index) { <li data-target="#divFormCarousel" data-slide-to="@slideCount" class="active"></li> } } } </ol>
提前致謝。
刪除輪播的class屬性,並在您自己的$(document).ready(function() {})
處理程序中使用$('#carouselId').carousel()
對其進行顯式初始化。 之后,立即發出$("#carouselId").carousel(number)
轉到特定的幻燈片。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.