Tips for enabling autoplay for videos in Owl Carousel

I am facing an issue with implementing autoplay functionality for videos in an owl carousel. Despite trying different solutions found online, including this Owl Carousel VIDEO Autoplay doesn’t work, I haven't been able to make it work. Additionally, I have a requirement where the carousel should not transition to the next slide when a user is typing in the comment section located in a textarea within each slide. How can I achieve this? Thank you.

  <div class="owl-carousel  owl-theme slideHeighlight">
              <div class="item">
                 <figure class="fig-highlight">
                    <img src="Images/high1.jpg" />
                       <figcaption>
                       <div class="highlight-cm">
                          <textarea class="txtarea-cm" rows="1" placeholder="send message"></textarea><button type="submit" class="btn btn-send btnhighlight" >send</button>
                       </div>
                    </figcaption>
                 </figure>
              </div>
              <div class="item">
                 <figure class="fig-highlight">
                    <img src="Images/high2.jpg" />
                    <figcaption>
                       <div class="highlight-cm">
                          <textarea class="txtarea-cm" rows="1" placeholder="send message"></textarea><button type="submit" class="btn btn-send btnhighlight" >send</button>
                       </div>
                    </figcaption>
                 </figure>
              </div>
              <div class="item item-video">
                 <figure class="fig-highlight">
                    <video>
                       <source src="Images/video2.mp4" type="video/mp4" />
                    </video>
                  <figcaption>
                       <div class="highlight-cm">
                          <textarea class="txtarea-cm" rows="1" placeholder="send message"></textarea><button type="submit" class="btn btn-send btnhighlight" >send</button>
                       </div>
                    </figcaption>
                 </figure>
              </div>
           </div>

Code snippet:

                $('.slideHeighlight').owlCarousel({
  rtl: true,
  margin: 10,
  nav: true,
  loop: false,
  autoplay: true,
  singleItem: true,
  video: true,
  responsive: {
     0: {
        items:1
     },
     567: {
        items:1
     },
     600: {
        items:1
     },
     900: {
        items: 1
     }

  }
   });

        $(document).on('click', '.slideHeighlight', function () {
       if ($(this).next().hasClass('item-video')) {
        $(this).find(".fig-highlight video").play();
       }
  });

Answer №1

If you're looking for a solution, consider implementing the following code snippet:

Check out the demo here

 owl.on('changed.owl.carousel', function(event) {
   $(".owl-item video").each(function(index, value) {
     this.pause();
     this.currentTime = 0;

   });
   $(".owl-item.active video").each(function(index, value) {
     this.play();
   });
 })

If the above doesn't work as expected, you may want to give this alternative approach a try:

$(".owl-item").each(function(index, value) {
     this.pause();
     this.currentTime = 0;
      this.play();
});

Answer №2

After discovering that some browsers are granted permission to autoplay video and sound without user interaction, I have added a play button for manual control.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a dropdown navigation menu

I am trying to create a smooth slide down menu effect, but it seems to instantly expand with no transition. Can anyone help me troubleshoot this issue? const Container = styled.section` position: relative; overflow: hidden; ` const WrapperItems = st ...

Store data in LocalStorage according to the selected value in the dropdown menu

Can you help me understand how to update the value of a localstorage item based on the selection made in a dropdown menu? <select id="theme" onchange=""> <option value="simple">Simple</option> <option valu ...

The class type "selectLabel" passed to the classes property in index.js:1 for Material-UI is not recognized in the ForwardRef(TablePagination) component

Just started using react and encountering a repetitive error in the console after adding this new component. Here is the full error message: Material-UI: The key selectLabel provided to the classes prop is not implemented in ForwardRef(TablePagination). ...

MUI version 5 - Checkboxes are receiving a variety of unique classes

After recently upgrading from Mui v4 to v5, I've noticed a strange behavior with checkboxes. Upon inspecting the DOM differences between the two versions, it appears that some additional classes are now being applied in v5 and the extra span with the ...

Acquire an array of Worksheet names in JavaScript by utilizing ActiveX

How can I retrieve a comprehensive list of all available sheet names from my Excel file using the ActiveX Object? I am aware that the code Excel.ActiveWorkBook.Sheets provides access to the sheets. However, how do I obtain an array containing the NAMES of ...

Ways to maximize the amount of content contained within a box

My current struggle involves meeting the requirements of my customers. I have a small box (230px x 200px) with an image that will display a list on hover. However, the customer now wants more items in the list than can fit in the box. Scrolling within the ...

Clearing the ng-model value in a controller following an ng-change event

Is there a way to reset the ng-model value in the controller after an ngChange event without needing to use a directive? <div ng-repeat="i in items"> <!-- Some DOM comes here --> <select ng-model="i.avail" ng-change="changeAvail(i. ...

Ensure that the flex item expands to occupy the vacant space left when other child elements are deleted

I am facing an issue with multiple children inside a parent container that has the CSS properties display: flex and flex-direction: column. There is a toggle button on the webpage which removes one of the children when clicked. The problem I need to solv ...

Adding hue to the portion of text following a JavaScript split() operation

I need assistance in printing the text entered in a textarea with different colors. I am separating the string using the split() method, which works fine. However, I now want to print the substrings in the textarea with colors. How can this be achieved? & ...

I'm encountering an error when trying to pass multiple parameters in an AJAX request

I am trying to pass three parameters to my ajax code. Here is the snippet of my code: $(document).ready(function () { SearchText(); }); function SearchText() { $("#txt712").autocomplete({ source: function (request, resp ...

The radar chart created with amchart.js disappears when placed within bootstrap columns

I'm encountering an issue while trying to display radar charts using amchart.js in bootstrap columns. The "amStockGraph" charts render perfectly, however, the radar charts appear blank with no errors in the console. Any advice on this matter would be ...

How can I retrieve form information using Jquery AJAX?

Hey there! I've been working on a code to retrieve key/value pairs from a form on a page when a user clicks submit. Despite trying various methods, I keep encountering errors like: Uncaught TypeError: Cannot use 'in' operator to search for ...

jquery blur function not triggering properly

I am not very familiar with jquery and javascript. Below is the code I have written for an input text field where I want to use blur function for validation: <div class="form-row form-input-name-row"> <label> <span>Full name& ...

Set a consistent pixel measurement for all images

I am working on a project where I have an image of a card that needs to be repeated 30 times. Each time the card is repeated, I want it to overlap with the previous card in a specific position, resembling a deck of cards. The issue I am facing is that whe ...

Issue with importing Node module (@pusher/push-notifications-web) occurring when page is refreshed in Next.js

Encountering a problem while trying to integrate the node module @pusher/push-notifications-web. More information can be found at https://github.com/pusher/push-notifications-web I'm unsure whether this issue is related to Next.js or the node module ...

Build a Node.js application with Express to host static files

I am attempting to provide my static files "web.html" and "mobile.html", but I want them to be served only if the user is accessing from a web or mobile device. After some research, I came up with this code: var express = require('express'); va ...

Display Mailchimp subscription form adjacent to button click on a WordPress website

Seeking assistance with integrating a MailChimp simple subscription form (requires email and submit) next to a button on my Wordpress page. The desired functionality is a straightforward button labeled "Newsletter." When clicked, a small form should conve ...

Underscore performs calculations and outputs a fresh object as a result

Here is an example of a time series: [ { "_id": { "action": "click", "date": "2015-02-02T00:00:00+01:00" }, "total": 5 }, { "_id": { "action": "hit", "date": "2015 ...

Upon each iteration, a new array must be generated using Jquery

When working with arrays in jQuery, I encountered an issue where the key and value were being added as an object instead of a new array or key within a loop. $.each($("input[type='time']"), function(){ var checkboxid = $(this).attr( ...

Implementing visibility toggles for objects in three.js using a graphical user interface

I am interested in controlling the visibility of objects in my scene through a button on a GUI. The following function currently hides/shows objects individually: g3white.traverse(function(child){child.visible = true;}); g3black.traverse(function(child){ ...