miriamdepaula

TWITCH: Responsive Livestream Embed

Mar 5th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.33 KB | None | 0 0
  1. //DEV REFERENCE: https://dev.twitch.tv/docs/embed
  2. //CSS
  3. .twitch-wrapper {position: relative;}
  4. #twitch-embed {position: relative;width:75%;}
  5. #twitch-embed:before{content: "";display: block;padding-top: 56.25%;}
  6. .twitch-chat{position: absolute;top: 0;bottom: 0;right: 0;width: 25%;}
  7. #twitch-embed iframe, .twitch-chat iframe {position: absolute;top: 0;left: 0;width: 100%;height: 100%;}
  8. @media (max-width: 1024px) {
  9.     #twitch-embed{
  10.         width:100%;
  11.     }
  12.     .twitch-chat{
  13.         /*display:none;*/  
  14.         position: relative;
  15.         clear: both;
  16.         height: 300px; 
  17.         width: 100%;       
  18.     }
  19. }
  20.  
  21. //HTML
  22. <div class='twitch-wrapper'>          
  23.    <div id="twitch-embed"></div>            
  24.    <div class='twitch-chat'>
  25.        <iframe frameborder="0" scrolling="no" src="https://www.twitch.tv/[YOUR TWITCH CHANNEL ID]/chat"></iframe>
  26.    </div>            
  27. </div>  
  28.  
  29. //JS
  30. <script src="https://embed.twitch.tv/embed/v1.js"></script>
  31. <script type="text/javascript">
  32.           var embed = new Twitch.Embed("twitch-embed", {
  33.             width: 854,
  34.             height: 480,
  35.             channel: "[YOUR TWITCH CHANNEL ID]",
  36.             layout: "video",
  37.             autoplay: false
  38.           });
  39.  
  40.           embed.addEventListener(Twitch.Embed.VIDEO_READY, () => {
  41.             var player = embed.getPlayer();
  42.             player.play();
  43.           });
  44.         </script>
Add Comment
Please, Sign In to add comment