Home >Web Front-end >JS Tutorial >Implementation code for DIV to scroll as the scroll bar scrolls [Recommended]_jquery

Implementation code for DIV to scroll as the scroll bar scrolls [Recommended]_jquery

WBOY
WBOYOriginal
2016-05-16 15:05:491164browse

I remember that writing this kind of code used to be troublesome, but now it’s much easier with JQuery. It only takes a few lines of code!

<script type="text/javascript" src="Js/jquery-1.7.2.min.js"></script> 
  <script type="text/javascript"> 
    $(function() { 
      $(window).scroll(function() { 
        var top = $(window).scrollTop()+200; 
        var left= $(window).scrollLeft()+320; 
        $("#editInfo").css({ left:left + "px", top: top + "px" }); 
      }); 
    }); 
  </script> 
 
  <div id="editInfo" style="float:left;width:300px;background-color:#ccc;position:absolute;top:200px;"> 
    <div>用户名:<input type="text" /></div> 
    <div>密码:<input type="text" /></div> 
    <div>年龄:<input type="text" /></div> 
    <div>备注:<input type="text" /></div> 
    <div><input type="button" value="保存" /></div> 
  </div> 

The above implementation code for DIV to scroll as the scroll bar scrolls [recommended] is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn