Coder Social home page Coder Social logo

ayastreb / jquery.youtube-inview-autoplay Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 2.0 4 KB

:tv: A jQuery plugin that starts playing YouTube video when it's scrolled into the view and stops it when it's scrolled out

License: MIT License

JavaScript 100.00%
jquery-plugin youtube youtube-autoplay

jquery.youtube-inview-autoplay's Introduction

YouTube in-view auto-play plugin

This plugin is using https://github.com/protonet/jquery.inview and YouTube Iframe API to setup multiple embeded YouTube players and starts playing them once the player is scrolled in browser view.

Usage

In page markup videos can be stored as <div> elements with data attributes, e.g:

<div class="youtube-video" 
     id="menorca-faro-de-favarix" 
     data-video-id="o2Fs6SoRHCk" 
     width="1000" 
     height="563"></div>

First, you need to load YouTube API. Then you need to apply plugin to all video elements:

<script type="text/javascript">
  // Load the IFrame Player API code asynchronously.
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/player_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  function onYouTubeIframeAPIReady() {
    $('.youtube-video').inViewAutoplay({
      autohide: 1,
      modestbranding: 1,
      rel: 0,
      quality: 'hd720'
    });
  }
</script>

In plugin call you can pass player parameters object, for a list of supported parameters see: https://developers.google.com/youtube/player_parameters#Parameters

jquery.youtube-inview-autoplay's People

Contributors

ayastreb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jquery.youtube-inview-autoplay's Issues

It's not work on iOS

Hi, thanks for great plugin. I can run it on android device, but it can't run on iOS device. Does anyone have a solution for me?

iPad bug?

Hi,

This is a really helpful plugin, though I've noticed a problem when testing on iPad – the video starts to load then appears to get stuck in a preload cycle and the video never autoplays (tested on your Menorca demo page – as it happens, I used to live in Menorca and got some good memories for your pictures, thanks!).

I tested using iOS 9.3.5.

Thanks,
Matt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.