{"id":173,"date":"2024-06-02T04:49:29","date_gmt":"2024-06-02T04:49:29","guid":{"rendered":"https:\/\/codebox.keyframetechsolution.com\/?p=173"},"modified":"2025-02-08T15:32:33","modified_gmt":"2025-02-08T15:32:33","slug":"play-video-on-scroll","status":"publish","type":"post","link":"https:\/\/codebox.keyframetechsolution.com\/play-video-on-scroll\/","title":{"rendered":"Build an Autoplay Video on Scroll Feature Using HTML CSS &#038; JavaScript"},"content":{"rendered":"<p>Adding an autoplay video that plays when a user scrolls can enhance engagement and create a more interactive web experience.<\/p>\n<p data-pm-slice=\"1 1 []\"><span data-preserver-spaces=\"true\">In this tutorial, <\/span><span data-preserver-spaces=\"true\">we&#8217;ll<\/span><span data-preserver-spaces=\"true\"> build a play video on scroll feature using HTML, CSS, and JavaScript.<\/span><\/p>\n<p>\u2705\u00a0<strong>Watch Live Preview<\/strong>\u00a0\ud83d\udc49\ud83d\udc49<\/p>\n<p><iframe title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/R8ztjYc7Xkw?si=OYbr-isJruX6umn-\" width=\"100%\" height=\"450\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"#conclusion\">Click Here to Download the Code<\/a><\/p>\n<h2><span data-preserver-spaces=\"true\">Why Use an Autoplay Video on Scroll?<\/span><\/h2>\n<p><span data-preserver-spaces=\"true\">Autoplay videos help grab <\/span><span data-preserver-spaces=\"true\">users&#8217;<\/span><span data-preserver-spaces=\"true\"> attention and can be <\/span><span data-preserver-spaces=\"true\">useful for<\/span><span data-preserver-spaces=\"true\">:<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">Showcasing product demos<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Enhancing storytelling on websites<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Making websites more interactive<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Improving user engagement without requiring manual play<\/span><\/li>\n<\/ul>\n<p><span data-preserver-spaces=\"true\">Now, <\/span><span data-preserver-spaces=\"true\">let\u2019s<\/span><span data-preserver-spaces=\"true\"> dive into the step-by-step guide.<\/span><\/p>\n<h2>Set Up Your Project Folder<\/h2>\n<p><span data-preserver-spaces=\"true\">Create a folder on your computer and add the following files inside it:<\/span><\/p>\n<ul>\n<li><strong><span data-preserver-spaces=\"true\">index.html<\/span><\/strong><\/li>\n<li><strong><span data-preserver-spaces=\"true\">style.css<\/span><\/strong><\/li>\n<li><strong><span data-preserver-spaces=\"true\">script.js<\/span><\/strong><\/li>\n<\/ul>\n<h2><strong><span data-preserver-spaces=\"true\">Source Code<\/span><\/strong><\/h2>\n<h3><strong><span data-preserver-spaces=\"true\">HTML Code<\/span><\/strong><\/h3>\n<div class=\"code-container\">\n<div class=\"toolbar\">\n<div class=\"actions\">\n        <span><\/span><br \/>\n        <span class=\"yellow\"><\/span><br \/>\n        <span class=\"green\"><\/span>\n      <\/div>\n<div class=\"title\">index.html<\/div>\n<\/p><\/div>\n<div class=\"code-content\">\n<pre><code class=\"language-markup\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n  &lt;meta charset=\"UTF-8\"&gt;\r\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\r\n  &lt;title&gt;How to Build an Autoplay Video on Scroll Using HTML CSS & JS&lt;\/title&gt;\r\n  &lt;link rel=\"stylesheet\" href=\"style.css\"&gt;\r\n  &lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/font-awesome\/4.7.0\/css\/font-awesome.min.css\"&gt;\r\n  &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.5.1.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/typed.js\/2.0.11\/typed.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/waypoints\/4.0.1\/jquery.waypoints.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/css\/bootstrap.min.css\"&gt;&lt;\/script&gt;\r\n  &lt;link rel=\"stylesheet\" href=\"https:\/\/fonts.googleapis.com\/css2?family=Poppins:wght@400;500;600;700&amp;family=Ubuntu:wght@400;500;700&amp;display=swap\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;!-- CODE --&gt;\r\n\r\n&lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.3.0-alpha1\/dist\/js\/bootstrap.bundle.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"script.js\"&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/code><\/pre>\n<\/p><\/div>\n<\/div>\n<h3>CSS Code<\/h3>\n<div class=\"code-container\">\n<div class=\"toolbar\">\n<div class=\"actions\">\n        <span><\/span><br \/>\n        <span class=\"yellow\"><\/span><br \/>\n        <span class=\"green\"><\/span>\n      <\/div>\n<div class=\"title\">style.css<\/div>\n<\/p><\/div>\n<div class=\"code-content\">\n<pre><code class=\"language-markup\">\r\n&lt; \/* Your CSS code here *\/ &gt;\r\n&lt; * { &gt;\r\n\r\n&lt; margin: 0; &gt;\r\n&lt; padding: 0 &gt;\r\n&lt; box-sizing: border-box; &gt;\r\n&lt;     text-decoration: none; &gt;\r\n&lt;     } &gt;\r\n      <\/code><\/pre>\n<\/p><\/div>\n<\/div>\n<h3>JavaScript Code<\/h3>\n<div class=\"code-container\">\n<div class=\"toolbar\">\n<div class=\"actions\">\n        <span><\/span><br \/>\n        <span class=\"yellow\"><\/span><br \/>\n        <span class=\"green\"><\/span>\n      <\/div>\n<div class=\"title\">script.js<\/div>\n<\/p><\/div>\n<div class=\"code-content\">\n<pre><code class=\"language-markup\">\r\n&lt; \/\/ JavaScript Code &gt;\r\n      <\/code><\/pre>\n<\/p><\/div>\n<\/div>\n<h2><span data-preserver-spaces=\"true\">How It Works<\/span><\/h2>\n<ul>\n<li><span data-preserver-spaces=\"true\">The script listens for scroll and resize events.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">It checks if video is within the viewport.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">If a video is visible, it plays automatically.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">If a video goes out of view, it pauses.<\/span><\/li>\n<\/ul>\n<h2><span data-preserver-spaces=\"true\">Enhancing User Experience<\/span><\/h2>\n<p><span data-preserver-spaces=\"true\">To further improve usability, you can add:<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\"><strong>Lazy Loading:<\/strong> Load the video only when it enters the viewport.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\"><strong>Custom Controls:<\/strong> Allow users to pause\/play manually.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\"><strong>Smooth Transitions:<\/strong> Fade effects when the <\/span><span data-preserver-spaces=\"true\">video<\/span><span data-preserver-spaces=\"true\"> starts\/stops.<\/span><\/li>\n<\/ul>\n<h2><span data-preserver-spaces=\"true\">Testing Your Feature<\/span><\/h2>\n<p><span data-preserver-spaces=\"true\">To test the functionality:<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">Open the HTML file in a browser.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Scroll down and check if the video plays when in view.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Scroll back up and see if it pauses.<\/span><\/li>\n<\/ul>\n<p><strong>You May Also Like &#8211;\u00a0<\/strong><a href=\"https:\/\/codebox.keyframetechsolution.com\/m3u8-player-html-code\/\">How to Create an M3U8 Player Using HTML CSS &amp; JavaScript<\/a><\/p>\n<h2 id=\"conclusion\"><span data-preserver-spaces=\"true\">Conclusion<\/span><\/h2>\n<p><span data-preserver-spaces=\"true\">You&#8217;ve<\/span><span data-preserver-spaces=\"true\"> successfully created a play video on scroll. This feature can greatly enhance your <\/span><span data-preserver-spaces=\"true\">website&#8217;s<\/span><span data-preserver-spaces=\"true\"> interactivity and engagement. Try experimenting with it and styles to suit your design.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Let me know if you need further improvements or customizations! \ud83d\ude80<\/span><\/p>\n<p><strong>19 people bought this<\/strong><\/p>\n<p><strong>Grab it Now for Just <i class=\"fa fa-rupee\" style=\"color:#046bd2;\"><\/i><span style=\"color:#046bd2;\">20<\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding an autoplay video that plays when a user scrolls can enhance engagement and create a more interactive web experience. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[88],"tags":[374,375,376],"class_list":["post-173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-designs","tag-play-video-on-scroll","tag-play-video-on-scroll-html","tag-play-video-on-scroll-javascript"],"acf":[],"_links":{"self":[{"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":9,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":1441,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/posts\/173\/revisions\/1441"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/media\/174"}],"wp:attachment":[{"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/media?parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/categories?post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codebox.keyframetechsolution.com\/wp-json\/wp\/v2\/tags?post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}