script.aculo.us Efecto ScrollTo

En este artículo, demostraremos el efecto de ScrollTo mediante el uso de la biblioteca de JavaScript llamada script.aculo.us que tiene una transición suave de uno a otro. También podemos ajustar la duración del efecto.

Sintaxis:

Effect.ScrollTo('element_id', { duration:'0.2', offset:-20 });

Nota: Para usar esta biblioteca, se supone que debemos instalar la biblioteca y luego usarla en nuestros programas. Y para hacerlo puedes seguir este enlace http://script.aculo.us/downloads .

Enfoque: Para demostrar el uso de esta función, hemos escrito un pequeño fragmento de código. Hemos escrito una pequeña función de JavaScript llamada método ShowEffect() que utiliza el método Effect.ScrollTo() de esta biblioteca. Al hacer clic en Click me to Scroll! , verás el efecto claramente.

Ejemplo: para ver el efecto, primero descargue la biblioteca y luego abra este programa en el entorno local.

HTML

<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" 
        src="prototype.js">
    </script>
  
    <script type="text/javascript" 
        src="scriptaculous.js">
    </script>
  
    <script type="text/javascript">
  
        function ShowEffect(element) {
            new Effect.ScrollTo(element, 
            { duration: '0.2', offset: -20 });
        }          
    </script>
</head>
  
<body>
    <h2>script.aculo.us Effect.ScrollTo</h2>
    <p>
        JavaScript is a lightweight, cross-platform 
        and interpreted scripting language.<br />
        It is well-known for the development of web 
        pages, many non-browser environments also 
        use it.<br />JavaScript can be used for 
        Client-side developments as well as 
        Server-side developments.<br />
    </p>
  
    <p>
        <b>Features of JavaScript:</b> According to
        a recent survey conducted by Stack Overflow,
        <br />JavaScript is the most popular language 
        on earth.<br />With advances in browser 
        technology and JavaScript having moved into 
        the server<br />with Node.js and other 
        frameworks, JavaScript is capable of so much 
        more.<br /> Here are a few things that we can 
        do with JavaScript:<br />
    </p>
  
    <p>
        JavaScript was created in the first place
        for DOM manipulation.<br /> Earlier websites 
        were mostly static, after JS was created
        dynamic Web sites were made.<br /> Functions 
        in JS are objects. They may have properties 
        and methods just like another object.<br />
        They can be passed as arguments in other 
        functions.<br />Can handle date and time.<br />
        Performs Form Validation although the forms are
        created using HTML.<br />No compiler needed.<br />
    </p>
  
    <p>
        JavaScript is a lightweight, cross-platform and
        interpreted scripting language.<br />
        It is well-known for the development of web pages,
        many non-browser environments also use it.<br />
        JavaScript can be used for Client-side
        developments as well as Server-side 
        developments.<br />
    </p>
  
    <p>
        <b>Features of JavaScript:</b> According
        to a recent survey conducted by Stack 
        Overflow,<br /> JavaScript is the most 
        popular language on earth.<br />
        With advances in browser technology and
        JavaScript having moved into the server<br />
        with Node.js and other frameworks,
        JavaScript is capable of so much more.<br />
        Here are a few things that we can do
        with JavaScript:<br />
    </p>
  
    <p>
        JavaScript was created in the first place
        for DOM manipulation.<br /> Earlier websites
        were mostly static, after JS was created 
        dynamic Web sites were made.<br />
        Functions in JS are objects. They may have
        properties and methods just like another
        object.<br /> They can be passed as arguments 
        in other functions.<br /> Can handle date 
        and time.<br />Performs Form Validation 
        although the forms are created using HTML.<br />
        No compiler needed.<br />
    </p>
  
    <p>
        JavaScript is a lightweight, cross-platform
        and interpreted scripting language.<br />
        It is well-known for the development of
        web pages, many non-browser environments
        also use it.<br /> JavaScript can be used
        for Client-side developments as
        well as Server-side developments.<br />
    </p>
      
    <p>
        <b>Features of JavaScript:</b> According to a
        recent survey conducted by Stack Overflow,<br />
        JavaScript is the most popular language on 
        earth.<br />With advances in browser technology 
        and JavaScript having moved into the server<br />
        with Node.js and other frameworks,JavaScript is
        capable of so much more.<br />Here are a few 
        things that we can do with JavaScript.<br />
    </p>
      
    <p>
        JavaScript was created in the first place for
        DOM manipulation.<br /> Earlier websites were
        mostly static,after JS was created dynamic 
        Web sites were made.<br />Functions in JS are 
        objects. They may have properties and methods 
        just like another object.<br />They can be 
        passed as arguments in other functions.<br />
        Can handle date and time.<br />
        Performs Form Validation although the forms are
        created using HTML.<br />
        No compiler needed.<br />
    </p>
      
    <p>
        JavaScript is a lightweight, cross-platform and
        interpreted scripting language.<br />
        It is well-known for the development of web pages,
        many non-browser environments also use it.<br />
        JavaScript can be used for Client-side developments
        as well as Server-side developments.<br />
    </p>
      
    <a href="#" onclick="ShowEffect('h2'); return false;">
        Click me to scroll!
    </a>
</body>
  
</html>

Producción:

Publicación traducida automáticamente

Artículo escrito por Jitender_1998 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *