如何用js返回顶部和跳转到所需位置及计时器

<!DOCTYPE html> <html> <head lang="en">     <meta charset="UTF-8">     <title></title>     <style>         * {             margin: 0;             padding: 0         }        p {             width: 400px;             font-size: 30px;             height: 300px;             background: blue;             border: solid 5px         }        .top {             position: fixed;             right: 0;             top: 300px         }        .tiao {             position: fixed;             right: 0;             top: 400px         }        .stop {             position: fixed;             right: 300px;             top: 500px         }     </style> </head> <body> <div class="stop"> <input type="button" value="star" onclick="t()"/> <input type="text" id="shijian"/> <input type="button" value="stop" onclick="stop()"/> </div> <div>     <input type="button" value="返回顶部" onclick="fanhu()" class="top"/>     <input type="button" value="跳转" onclick="tiao()" class="tiao"/>    <p>1楼</p>    <p>2楼</p>    <p>3楼</p>    <p>4楼</p>    <p>5楼</p>    <p>6楼</p>    <p>7楼</p>    <p>8楼</p>    <p>9楼</p>    <p>10楼</p>    <p>11楼</p>    <p>12楼</p>    <p>13楼</p>    <p>14楼</p>    <p>15楼</p>    <p>16楼</p></div> </body> <script type="text/javascript">     function fanhu() {         window.scrollTo(0, 0)     }     function tiao() {         window.scrollBy(0, 310)     }     function t(){       setInterval("star()", 100);     }       var i=21;         function star(){             i=i-1;             if(i>=0&&i<=20){                 document.getElementById("shijian").value=i;            }             else{                 clearInterval("shijian")             }         }     function stop(){         i=-1     } </script> </html>
时间: 2025-01-02 03:58:32

如何用js返回顶部和跳转到所需位置及计时器的相关文章

[转] JS 返回顶部

仿新浪微博返回顶部的js实现(jQuery/MooTools) by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1576 一.引言 在web页面中,如果页面较高,为了方便用户快速地返回顶部,都会添加一个返回顶部按钮.例如: 其中淘宝网的是要滚动条的滚动距离大于某一段距离才显示返回顶部按钮:人人网的返回顶部直接在底部的工具条上:新浪微博的返回顶部在滚动高度大于0的时候显示

js&quot;返回顶部&quot;功能实现

JS代码: <script src="../../static/js/base/jquery/jquery.min.js"></script> <script>//当滚动条的位置处于距顶部100像素以下时,跳转链接出现,否则消失$(function () { $("#sidepanel").fadeOut(100); $(window).scroll(function(){ if ($(window).scrollTop()>

原生JS返回顶部,带返回效果

有些网站当滑到一定高度时右下角会有一个按钮,你只要一点就可以直接返回顶部了.那这个功能是怎么做到的呢.其实不算太难: 首先我们先在网页中创建一个按钮,上面写上返回顶部,把它的样式改成固定定位,之后想要什么样式都可以自己写上,再在上面设置一个id: 之后我们js中获取一下这个按钮的id,并且定义一个变量timer,方便接下来清除间隔器: 之后我们设置一个页面的滚动事件,在里面定义一个变量获取一下所滚动的高度: 再用一个判断语句来判断一下滚动的高度:我们在设置一个数来让按钮什么时候显示: var o

js返回顶部效果

当用户浏览的网页过于长的时候,用户在浏览到网页底部想要在返回顶部需要滚动好几次滚轮才能返回顶部,不仅麻烦,而且用户体验也会很差.现在的大多是页面都会在页面顶部或者是页面的可见区域的某一位置固定一个按钮,点击它可以使页面返回顶部,用户再也不用滚动滚轮了.下面我总结了集中常用的返回顶部的效果: 方法一(最简单,代码量最少,但是效果有些生硬).代码如下: 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <

js返回顶部小Demo

<style> .divH { height: 1800px; } .divT { width: 50px; height: 50px; font-size: 18px; background-color: #2F4F4F; text-align: center; color: white; position: fixed; right: 18px; bottom: 18px; } .divT:hover{ cursor: pointer; } .hide { display: none; }

js 返回顶部

function gotoTop(min_height){ var gotoTop_html = '<div id="gotoTop"></div>';//定义返回顶部的html标签,默认隐藏 $("body").append(gotoTop_html);//将元素插入页面 $("#gotoTop").click(function(){//定义返回顶部元素的点击事件 $('html,body').animate({scro

js返回顶部

/*  * 返回顶部 *<a class="go-top" id="goTop" href="javascript:;"></a> * 注:a链接需设置背景图片,或者其他可显示的返回顶部   */    var $t = $( '#goTop' );    var $h = 320;    if ( !$t.length ) {        return;    }    var handler = function(

js返回顶部动画效果

// 返回顶部 function goTop(){ // 无动画效果 document.body.scrollTop = 0; document.documentElement.scrollTop = 0; // 简单动画效果 $("html,body").animate({scrollTop:0},500); // 由快到慢的效果 scrollToptimer = setInterval(function () { console.log("定时循环回到顶部")

返回顶部的功能 div固定在页面位置不变

1.你在网上搜索的时候,可能会搜索到div固定在页面上,不随滚动条滚动而滚动是用CSS写的,写法是position:fixed;bottom:0; 但是这个在iframe满地跑的页面实际开发中,有啥用呢?反正我用了感觉没啥用. 2.还有一种就是JS控制了.我写的是随着滚动滚动 ,计算div的绝对与可视页面的位置不变. $(window.parent).on('scroll',function(){ $(返回顶部所在div选择器).css('top',parent.document.documen