<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1{
width:30px;
height:500px;
background:#000;
position:absolute;
left:10px;
top:10px;
}
#div2{
width:30px;
height:30px;
position:absolute;
background:red;
left:0px;
top:0px;
}
#div3{
width:498px;
border:1px #ccc solid;
height:498px;
position:absolute;
left:50px;
top:10px;
overflow:hidden;
}
#div4{
position:absolute;
}
textarea{
position:absolute;
left:50px;
top:550px;
width:500px;
height:200px;
}
</style>
<script>
window.onload = function ()
{
var odiv1 = document.getElementById('div1');
var odiv2 = document.getElementById('div2');
var odiv3 = document.getElementById('div3');
var odiv4 = document.getElementById('div4');
var otext = document.getElementsByTagName('textarea')[0];
var ratio = odiv3.clientHeight / odiv4.offsetHeight > 1 ? 1 : odiv3.clientHeight / odiv4.offsetHeight; function barheight()
{
var ratio = odiv3.clientHeight / odiv4.offsetHeight > 1 ? 1 : odiv3.clientHeight / odiv4.offsetHeight;
odiv2.style.height = odiv1.clientHeight * ratio + 'px';
} barheight(); otext.onkeyup = function ()
{
odiv4.innerHTML = otext.value;
barheight();
} odiv2.onmousedown = function (ev)
{
var ev = ev || event;
var diy = ev.clientY - this.offsetHeight;
if(odiv2.setCapture)
{
odiv2.setCapture();
}
document.onmousemove = function (ev)
{
var ev = ev || event;
var T = ev.clientY - diy;
var maxTop = odiv1.offsetHeight - odiv2.offsetHeight; if(T < 0 )
{
T = 0;
}
if(T > maxTop)
{
T = maxTop;
}
odiv2.style.top = T + 'px';
odiv4.style.top = (odiv3.clientHeight - odiv4.offsetHeight)*(T/maxTop) + 'px'; }; document.onmouseup = function ()
{
document.onmousedown = document.onmousemove = null;
if(odiv2.releaseCapture)
{
odiv2.releaseCapture();
}
} return false; }
};
</script>
</head> <body>
<div id="div1">
<div id="div2"></div>
</div>
<div id="div3">
<div id="div4"></div>
</div>
<textarea placeholder="请在文本框输入文字"></textarea>
</body>
</html>

dom 输入文字模拟滚动的更多相关文章

  1. Java Swing 如何添加输入文字并且可以滚动的文本框?( JTextArea ,JScrollPane的使用)

    准备: JTextArea 文本区,一个可以输入文字的文本框 常用方法: 1.setText(String t)设置文本区中显示的文本 2.getText() 获取文本区中显示的文本 JScrollP ...

  2. 微信小程序tips集合:无法输入文字/随时查看页面/元素审查/点击事件/数据绑定

    1:编辑文档无法输入文字 出现这种情况一般是因为之前编辑的文档未保存,所有在其他文档输入的时候会自动输入到未保存的文档中,在文档暂时编辑完毕后要ctrl+s随手保存,不然会出现无法打字情况 2: 随时 ...

  3. 利用js来实现文字的滚动(也就是我们常常见到的新闻版块中的公示公告)

    首先先看一下大致效果图(因为是动态的,在页面无法显示出来) 具体的实现代码如下: 1.首先是css代码: <style type="text/css"> body,ul ...

  4. js 实现文字列表滚动效果

    今天要实现抽奖名单在首页滚动展示的效果,就用js写了一个,代码如下: html代码: <style type="text/css"> *{margin:;padding ...

  5. iOS webView与js交互在文本空格上输入文字

    项目要求:webview加载html网址,内容为填空题型文本,需要在横线上添加答案,并点击提交按钮后再将答案进行回显 正常加载的效果图片: 这个是用js交互后的效果图: 点击空格,输入想输入的答案,如 ...

  6. jQuery实现公告文字左右滚动

    jQuery实现公告文字左右滚动的代码. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...

  7. jquery文字上下滚动的实现方法

    jquery实现文字上下滚动的方法. 代码: //上下滚动var textRoll=function(){$('#notice p:last').css({'height':'0px','opacit ...

  8. jquery文字左右滚动

    实现jquery文字左右滚动 <div class="fl">中奖名单:</div> <div class="scrollText" ...

  9. jquery 文字向上滚动+CSS伪类before和after的应用

    汇总常用技巧——CSS伪类before和after的应用 先上效果图,建议遵循有图有真相的原则,可以上图的地方,还望不要嫌麻烦,毕竟有图的话 可以让读者少花些时间! <!DOCTYPE html ...

随机推荐

  1. java 字符串函数

    string1.equals(string2) 比较字符串 substring()它有两种形式,第一种是:String substring(int startIndex)第二种是:String sub ...

  2. 使用.9.png报错 Exception raised during rendering

    Exception raised during rendering: Index: 2, Size: 2Exception details are logged in Window > Show ...

  3. js之json

    关于json不了解的,请点击:http://www.json.org/json-zh.html json对象的属性必须要用双引号,值为字符串类型也只能使用双引号,例:{"name" ...

  4. 51nod1431 快乐排队

    神???.我们可以发现无论怎么交换ai+i都是不变的.那么这样就可以了 #include<cstdio> #include<cstring> #include<cctyp ...

  5. HDU 1058 Humble Numbers【DP】

    题意:给出丑数的定义,只含有2,3,5,7这四个素数因子的数称为素数.求第n个丑数. 可以先观察几个丑数得出规律 1:dp[1] 2:min(1*2,1*3,1*5,1*7) 3:min(2*2,1* ...

  6. HDU 5273 Dylans loves numbers(水题)

    题意:给出一个0≤N≤1018,求其二进制中有几处是具有1的,假设相连的1只算1处,比如1101011就是3处. 思路:一个个数,当遇到第一个1时就将flag置为1:当遇到0就将flag置为0.当遇到 ...

  7. UVa120 - Stacks of Flapjacks

    Time limit: 3.000 seconds限时:3.000秒 Background背景 Stacks and Queues are often considered the bread and ...

  8. 【英语】Bingo口语笔记(73) - 以tly,tely结尾的误读

  9. vim 大小写转化命令

    vim中大小写转化的命令是<blockquote>gu或者gU</blockquote>形象一点的解释就是小u意味着转为小写:大U意味着转为大写. 剩下的就是对这两个命令的限定 ...

  10. RAC 环境下修改归档模式

    RAC环境下的归档模式切换与单实例稍有不同,主要是共享存储所产生的差异.在这种情况下,我们可以将RAC数据库切换到非集群状态下,仅仅在一个实例上来实施归档模式切换即可完成RAC数据库的归档模式转换问题 ...