dom 输入文字模拟滚动
<!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 输入文字模拟滚动的更多相关文章
- Java Swing 如何添加输入文字并且可以滚动的文本框?( JTextArea ,JScrollPane的使用)
准备: JTextArea 文本区,一个可以输入文字的文本框 常用方法: 1.setText(String t)设置文本区中显示的文本 2.getText() 获取文本区中显示的文本 JScrollP ...
- 微信小程序tips集合:无法输入文字/随时查看页面/元素审查/点击事件/数据绑定
1:编辑文档无法输入文字 出现这种情况一般是因为之前编辑的文档未保存,所有在其他文档输入的时候会自动输入到未保存的文档中,在文档暂时编辑完毕后要ctrl+s随手保存,不然会出现无法打字情况 2: 随时 ...
- 利用js来实现文字的滚动(也就是我们常常见到的新闻版块中的公示公告)
首先先看一下大致效果图(因为是动态的,在页面无法显示出来) 具体的实现代码如下: 1.首先是css代码: <style type="text/css"> body,ul ...
- js 实现文字列表滚动效果
今天要实现抽奖名单在首页滚动展示的效果,就用js写了一个,代码如下: html代码: <style type="text/css"> *{margin:;padding ...
- iOS webView与js交互在文本空格上输入文字
项目要求:webview加载html网址,内容为填空题型文本,需要在横线上添加答案,并点击提交按钮后再将答案进行回显 正常加载的效果图片: 这个是用js交互后的效果图: 点击空格,输入想输入的答案,如 ...
- jQuery实现公告文字左右滚动
jQuery实现公告文字左右滚动的代码. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...
- jquery文字上下滚动的实现方法
jquery实现文字上下滚动的方法. 代码: //上下滚动var textRoll=function(){$('#notice p:last').css({'height':'0px','opacit ...
- jquery文字左右滚动
实现jquery文字左右滚动 <div class="fl">中奖名单:</div> <div class="scrollText" ...
- jquery 文字向上滚动+CSS伪类before和after的应用
汇总常用技巧——CSS伪类before和after的应用 先上效果图,建议遵循有图有真相的原则,可以上图的地方,还望不要嫌麻烦,毕竟有图的话 可以让读者少花些时间! <!DOCTYPE html ...
随机推荐
- Volley HTTP库系列教程(3)自定义RequestQueue和编写单例RequestQueue示例
Setting Up a RequestQueue Previous Next This lesson teaches you to Set Up a Network and Cache Use a ...
- leetcode:Search for a Range(数组,二分查找)
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- CreateCompatibleDC与CreateCompatibleBitmap
函数功能:该函数创建一个与指定设备兼容的内存设备上下文环境(DC). 函数原型:HDC CreateCompatibleDC(HDC hdc): 参数: hdc:现有设备上下文环境的句柄,如果该句柄为 ...
- 【Todo】深入PHP内核系列
看到一个<深入PHP内核>系列,Todo: http://www.csdn.net/article/2014-09-15/2821685-exploring-of-the-php [问底] ...
- 【笨嘴拙舌WINDOWS】实践检验之屏幕取色
实践是检验真理的唯一标准 要取得屏幕的颜色,首先需要创建一个屏幕DC,然后使用该DC,调用GetPixel就可以了 "Note:GetPixel传入的DC应该是屏幕的DC,而不是桌面的DC, ...
- 解决 border-radius 元素在应用了 transform 的子元素 时overflow:hidden 失效的问题
受大家启迪,于是最近深入研究了一下Css3中的一些属性.之中也是碰到了个不为我知的问题,在这里特此总结并与大家分享. 问题重现:在父元素上应用了 border-radius 的圆角属性.加上 ove ...
- 快速掌握 Android Studio 中 Gradle 的使用方法 [转http://blog.csdn.net/feelang/article/details/41783317]
Gradle是可以用于Android开发的新一代的 Build System, 也是 Android Studio默认的build工具. Gradle脚本是基于一种JVM语言 -- Groovy,再加 ...
- KVC和KVO的区别
kvc和kvo 1.kvc Key-Value Coding (KVC) KVC,即是指 NSKeyValueCoding,一个非正式的 Protocol,提供一种机制来间接访问对象的属性.KVO 就 ...
- 20160206.CCPP体系详解(0016天)
代码片段(01):.指针.c+02.间接赋值.c 内容概要:内存 ///01.指针 #include <stdio.h> #include <stdlib.h> //01.取地 ...
- python练习程序(显示图像)
import matplotlib as mpl import Image import numpy as np import matplotlib.pyplot as plt im=Image.op ...