当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


script.aculo.us ScrollTo效果用法及代码示例


在本文中,我们将通过使用名为script.aculo.us的JavaScript库(从一个平滑过渡到另一个平滑过渡)来演示ScrollTo的效果。我们也可以调整效果的持续时间。

用法:

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

注意:要使用此库,我们应该先安装该库,然后在程序中使用它。为此,您可以点击此链接http://script.aculo.us/downloads。

方法:为了演示该函数的用法,我们编写了一小段代码。我们编写了一个名为ShowEffect()方法的小型JavaScript函数,该函数使用此库的Effect.ScrollTo()方法。通过单击“单击我滚动”,您将清楚地看到效果。

例:要查看效果,请先下载该库,然后在本地环境中打开此程序。



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>

输出:

相关用法


注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 script.aculo.us ScrollTo Effect。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。