السلام عليكم ... جربت اكثر من طريقة لدي عنوان وسيكشن استخدمت عليهم الhref and id للنقر والسكرول ولكن العجيب ان السكرول يحدث فقط اذا كنت اعلى من السيكشن المحدد اما اذا كنت اسفل ذلك السيكشن فلا حدث شيئ
في ال javaScript
من المفترض أن تعمل معك ميثود scrollIntoView بشكل طبيعي، وإليك مثال:
<!DOCTYPE html> <html> <style> #myDIV { height: 250px; width: 250px; overflow: auto; background: coral; } #content { margin:500px; height: 800px; width: 2000px; background-color: coral; } </style> <body> <h1>The Element Object</h1> <h2>The scrollIntoView() Method</h2> <button onclick="myFunction()">Scroll</button> <p>Click "Scroll" to scroll to the top of the element with id="content".</p> <div id="myDIV"> <div id="content"> <p>Some text inside an element.</p> <p>Some text inside an element.</p> <p>Some text inside an element.</p> </div> </div> <script> function myFunction() { const element = document.getElementById("content"); element.scrollIntoView(); } </script> </body> </html>
اضغط على زر scroll وسيتم الإنتقال للعنصر content
التعليقات