How To Play Pause Video On Scroll June 13, 2023 Post a Comment I want to play or pause video on scroll, if scroll is greater than 300 it should pause otherwise it should play. This is my video tag Solution 1: You need to bind your function to the scroll event and also change from autoplay to actually play() - pause(), check this example snippet: Note: I have changed from 300 to 70 just for the example but you can keep your breakpoint as you want var myvid = $('#myVid')[0]; $(window).scroll(function(){ var scroll = $(this).scrollTop(); scroll > 70 ? myvid.pause() : myvid.play() })Copybody { background:#e1e1e1; height:1000px; } video { display:block; width:300px; margin:0 auto; }Copy<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><videoid="myVid"width="100%"controlsautoplay><sourcetype="video/mp4"src="http://html5demos.com/assets/dizzy.mp4"></video>CopySolution 2: I have just improve this, for single video,onscroll video pause... This is html file video.htmlBaca JugaWhat's The Best Way To Add Html Dynamically With Jquery?Sound Notifications In OperaGoogle Maps V3 Javascript Works Only In Chrome?refer this link https://codepen.io/prashujack/pen/Jvmgxz Thank you. <!-- This is javascript file vdo.js --> "use strict"; var wrapper = $('.wrapper'); wrapper.scrollTop(50); var vid2=document.getElementById("movie2"); wrapper.scroll(function(){ var st = wrapper.scrollTop(); if (st > 10) {vid2.pause();$("#movie2").addClass("animated hinge");} else {vid2.play(); $("#movie2").removeClass("animated hinge");} });Copy<!-- This is css file --> .wrapper{ width: 400px; height: 600px; margin:20px auto; text-align:center; border:1px dashed grey; overflow-y: scroll; }Copy<!-- This is html file video.html--><html><head><metacharset="utf-8"><title>Untitled Document</title><scriptsrc="https://code.jquery.com/jquery-3.3.1.min.js"integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="crossorigin="anonymous"></script></head><body><divclass="wrapper"><videoid="movie2"width="320"height="180"preloadautoplay><sourcesrc="http://html5demos.com/assets/dizzy.mp4"type="video/mp4"> Your browser does not support the video tag. </video><br /><br/><p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur porro temporibus minima optio, labore perferendis, provident eveniet aliquid commodi dolorum debitis! Placeat porro omnis nam quod aut, enim quos optio laudantium repellendus eos soluta nostrum cumque mollitia neque ab dolores facere aliquam at voluptas. Cumque quam iste rerum odit veritatis tempore dolor aliquid, ex animi earum fugiat assumenda, voluptas deleniti sunt mollitia! Et obcaecati commodi, sed voluptatibus doloremque aperiam possimus quos nisi nulla veniam odit! Vitae optio debitis incidunt at doloremque eos earum maxime iusto nostrum excepturi, ipsum porro, aliquid architecto sed laboriosam fuga totam ut modi ipsa sit reprehenderit, iure magni unde. </p></div><!--endf of wrapper div--><scriptsrc="../Unnamed Site 2/vdo.js"></script></body></html>Copy Share You may like these postsMediaelementjs - How To Get A Wmv File To PlayHtml - Downloaded Multiple TimesHow To Add Events To Flash Fallback For Medialemetn And What Evets Are Available?Html5 Video Color Difference Chrome & Internet Explorer Post a Comment for "How To Play Pause Video On Scroll"
Post a Comment for "How To Play Pause Video On Scroll"