javascript - If section has class than start playing video -


please me make video play automatically when @ moment of scrolling on #video-section appeared .visible class name․ , vice versa, when .visible class name removed section, video stoped. thanks.

<section class="cd-section">         content </section> <section id="video-section" class="cd-section">     <video>         <source src="http://www.w3schools.com/tags/movie.mp4" type="video/mp4">     </video> </section> <section class="cd-section">         content </section> 

jsfiddle here https://jsfiddle.net/y896ec5x/

what you're doing (based on comments):

$("video").play(); // or $("video").pause(); 

is invalid, jquery doesn't have these functions natively.

try using $.get method, returns regular javascript dom object of element:

$("video").get(0).play(); // or $("video").get(0).pause(); 

then detect @ scrolling (parallax site without scrollbar), wrap in wheel event handle that:

$("html, body").bind("mousewheel", function(){   if ($("#video-section").hasclass("visible")) {     $("video").get(0).play()   } else {     $("video").get(0).pause();   } }); 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -