Sebbo Posted January 21 Posted January 21 I tried various ways to add this code, but it's just not working. I tried adding it with the code block so far. Technique I used: Put the HTML section from the code pen directly in the block. After the html code add the css part inside <style> </style> blocks add the JS bit after that inside <script> </script> tags No worky. Here's the Codepen: https://codepen.io/josephwong2004/pen/NWRGxdR Any solutions? THANK YOU!
tuanphan Posted January 23 Posted January 23 Because your Codepen link uses SCSS, not CSS, so it won't work when you pasted directly to Code Block. And you need to declare jQuery library Add a Code Block > paste this new code <div class='tp-container'> <div class='img background-img'></div> <div class='img foreground-img'></div> <input type="range" min="1" max="100" value="50" class="slider" name='slider' id="slider"> <div class='slider-button'></div> </div> <style> .tp-container { box-sizing: border-box; } .tp-container *, .tp-container *:before, .tp-container *:after { box-sizing: inherit; } .tp-container { position: relative; width: 900px; height: 600px; border: 2px solid white; } .tp-container .img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-size: 900px 100%; } .tp-container .background-img { background-image: url("https://i.imgur.com/s08MkXC.jpg"); } .tp-container .foreground-img { background-image: url("https://i.imgur.com/PfIWek4.jpg"); width: 50%; } .tp-container .slider { position: absolute; -webkit-appearance: none; appearance: none; width: 100%; height: 100%; background: rgba(242, 242, 242, 0.3); outline: none; margin: 0; transition: all 0.2s; display: flex; justify-content: center; align-items: center; } .tp-container .slider:hover { background: rgba(242, 242, 242, 0.1); } .tp-container .slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 6px; height: 600px; background: white; cursor: pointer; } .tp-container .slider::-moz-range-thumb { width: 6px; height: 600px; background: white; cursor: pointer; } .tp-container .slider-button { pointer-events: none; position: absolute; width: 30px; height: 30px; border-radius: 50%; background-color: white; left: calc(50% - 18px); top: calc(50% - 18px); display: flex; justify-content: center; align-items: center; } .tp-container .slider-button:after { content: ""; padding: 3px; display: inline-block; border: solid #5D5D5D; border-width: 0 2px 2px 0; transform: rotate(-45deg); } .tp-container .slider-button:before { content: ""; padding: 3px; display: inline-block; border: solid #5D5D5D; border-width: 0 2px 2px 0; transform: rotate(135deg); } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> <script> $("#slider").on("input change", (e)=>{ const sliderPos = e.target.value; // Update the width of the foreground image $('.foreground-img').css('width', `${sliderPos}%`) // Update the position of the slider button $('.slider-button').css('left', `calc(${sliderPos}% - 18px)`) }); </script> Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)
Sebbo Posted January 23 Author Posted January 23 You're a genius! However now I want to add 6 of these on one page. What needs to change in the code?
tuanphan Posted January 28 Posted January 28 On 1/24/2024 at 3:51 AM, Sebbo said: You're a genius! However now I want to add 6 of these on one page. What needs to change in the code? Just repeat this On 1/24/2024 at 3:57 AM, Sebbo said: Also, how do I remove this Script Disabled text? It is a default message in edit mode. In edit mode, your code will be disabled to prevent some problems when editing page Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment