简体   繁体   中英

How can I get all my links to scroll to the top of the page by placing one function in a coldfusion code

This is the function that I currently have. Instead of one link I want all my links to scroll to the top of the page. The function is to be placed within a coldfusion code.

<script>
function ScrollClick() {
         // Scroll to top

                 document.body.scrollTop = document.documentElement.scrollTop = 0;

        // Open up a link in my iframe
 document.getElementById('MainWindow').src="DocDisplayCategory.cfm?categoryID=89"
            }
</script>   
</li>

Here's how you'd do it with jQuery, in case that's an option for you:

$("body").on("click", "a", function(){
  $("html, body").animate({ scrollTop: 0 }, "slow");
});

http://jsfiddle.net/sL2vA/2/

UPDATE: To help clear up confusion regarding ColdFusion, you'd simply add this to the head of your template (assuming jQuery isn't already available):

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>

And put the above code wherever appropriate in your application (in the template footer, in an external JS file, whatever). Wrap it in a script tag if it's in the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM