JavaScript DHTML/jQuery/fadeTo

Материал из Web эксперт
Перейти к: навигация, поиск

Fade to a certain opacity

   
<html>
  <head>
    <style>
      .test{ border: 1px solid red; }
    </style>
  
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
         
         $("p:parent").fadeTo(1500, 0.3);
    });
    </script>

  </head>
  <body>
      <div><p>paragraph in div</p></div>
      <div>div</div>

  </body>
</html>



Fade to callback

   
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div").fadeTo(250, Math.random(),function () {
              alert("done");
            });
         
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me</div>
    </body>
</html>



Fade to in milliseconds

   
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div").fadeTo(250, Math.random());
        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me</div>
    </body>
</html>



Fade to random

   
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                  $("div").fadeTo("fast", Math.random());


        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me</div>

    </body>
</html>



fadeTo(speed, opacity, callback): Only the opacity is adjusted for this animation

 
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                
            $("p:first").click(function () {
              $(this).fadeTo("slow", 0.33);
            });
        });
    </script>
  </head>
  <body>
    <body>
      <p><span>asdf</span></p>
    </body>
</html>



Fast fade to

   
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                  $("div").fadeTo("fast", Math.random());


        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me</div>

    </body>
</html>



Slow fade to

   
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
                  $("div").fadeTo("slow", 0.33);


        });
    </script>
  </head>
  <body>
    <body>
          <div>Click me</div>

    </body>
</html>