运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body style="background: #f3f3f3 url('img_tree.png') no-repeat fixed right top;"> <h1>HTML Style Object</h1> <h2>The backgroundAttachment Property</h2> <p><b>Tip:</b> Try to to resize the window if the scrollbar is not available.</p> <p>Click the button to toggle between scroll and fixed position.</p> <p><b>Tip:</b> Scroll the page before and after you have clicked the button.</p> <button id="toggle" onclick="myFunction();">Set image to scroll</button> <p> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> Some text to enable scrolling. <br><br><br><br> </p> <script> function myFunction() { let x = document.body.style.backgroundAttachment; document.getElementById("toggle").innerHTML=(x=="scroll")? "Set bg image to scroll!":"Set bg image to fixed!"; document.body.style.backgroundAttachment=(x=="scroll")? "fixed":"scroll"; } </script> </body> </html>