Jquery-css-scrollleft

提供:Dev Guides
移動先:案内検索

jQuery-scrollLeft()メソッド

説明

  • scrollLeft()*メソッドは、最初に一致した要素のスクロール左オフセットを取得します。

このメソッドは、表示要素と非表示要素の両方で機能します。

構文

このメソッドを使用するための簡単な構文は次のとおりです-

selector.scrollLeft( )

パラメーター

これは、この方法で使用されるすべてのパラメータの説明です-

  • NA

以下は、このメソッドの使用方法を示す簡単な例です-

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript"
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>

      <script type = "text/javascript" language = "javascript">
         $(document).ready(function(){
            $("div.demo").scrollLeft( 200 );

            $("div.demo").mousemove(function () {
               var left = $("div.demo").scrollLeft();
               $("#result")l("left offset: <span>" + left + "</span>.");
            });

         });
      </script>

      <style>
         div.demo {background:#CCCCCC none repeat scroll 0 0;
            border:3px solid #666666;
            margin:5px; padding:5px; position:relative; width:200px;
            height:100px; overflow:auto;}
         div.result{margin:10px; width:100px; height:100px; margin:5px;
            float:left; background-color:blue;}
         p { margin:10px; padding:5px; border:2px solid #666;
            width:1000px; height:1000px;}
      </style>
   </head>

   <body>
      <div class = "demo"><p>Hello</p></div>
      <span>Scroll horizontal  button to see the result:</span>
      <div class = "result"><span id = "result"></span></div>
   </body>
</html>

これにより、次の結果が生成されます–