您的位置:

js和canvas实现数字滚动,canvas 滚动条

js和canvas实现数字滚动,canvas 滚动条

更新:

本文目录一览:

Unity3d如何实现滚动文本框

一、在Canvas新建一个Panel,add scroll Rect和mask组件,Rect Transform设成 middle-center,因为这样才能设置大小和text控件相同大小

二、Panel下新建一个Text,Vertical Overflow设置成Overflow,然后add Content Size Fitter这个Layout,该Layout的Vertical Fit设置为Perferred Size,然后调整大小和在Panel中的位置

三、新建一个ScrollBar,不在Panel之下,和Panel并列,Direction设置成Bottan to Top。设置成Panel同样的高度,并挨在一起,这样看起来就是一个文本框右边带着一个垂直滚动条

四、Panel的Scroll Rect组件的Content指定Text,Vertical Scrollbar指定上面新建的ScrollBar。

如何实现canvas的图片轮播

图片自动滑动效果很多网站都要用,最近在学html5就拿这个练练手,发现用canvas实现起来其实很简单。代码比较粗糙,有很多改进的地方,不过还是先记录一下。

一. html文件

[html] view

plaincopy

!DOCTYPE html

html lang="en"

head

meta charset="utf-8"/

titleHTML5 Images Slider/title

script src=""/script

script src="test.js"/script

link href="style.css" rel="stylesheet" /

/head

body

div id="container"

canvas id="imgs" width="500" height="300" onclick="canvasClick()"/canvas

/div

div class="imgGallery"

span class="cover"img src="1.jpg" id="img1" width="125" height="150" onclick="iconClick(this.id)"/span

img src="2.jpg" id="img2" width="125" height="150" onclick="iconClick(this.id)"

img src="3.jpg" id="img3" width="125" height="150" onclick="iconClick(this.id)"

img src="4.jpg" id="img4" width="125" height="150" onclick="iconClick(this.id)"

/div

/body

footer

/footer

/html

二. js文件,名字test.js

[javascript] view

plaincopy

var images = new Array();

var cIndex = 0;

var speed = 5;

var context;

var canvas;

var currentImage;

var width=300;

var height=300;

var stopX = 95;

var stopY = 0;

var autoTimeout;

var manuTimeout;

var interval;

var img1;

var img2;

var img3;

var img4;

var timeoutInterval = 5;

function slideImage(id,x,y,imgObj){

this.speed = speed;

this.preImage = null;

this.nextImage = null;

this.imgObj=imgObj;

this.x=x;

this.y=y;

this.direction="right";

this.id = id;

}

function buttonNext(x,y,bwidth,bheight){

this.x = x;

this.y = y;

this.width = bwidth;

this.height = bheight;

}

$(document).ready(

function(){

InitImages();

canvas = document.getElementById("imgs");

context = canvas.getContext("2d");

//移动图片

context.drawImage(currentImage.imgObj,currentImage.x,currentImage.y,width,height);

context.drawImage(currentImage.preImage.imgObj,currentImage.preImage.x,currentImage.preImage.y,width,height);

context.drawImage(currentImage.nextImage.imgObj,currentImage.nextImage.x,currentImage.nextImage.y,width,height);

context.fillStyle="rgba(100,150,185,0.5)";

context.fillRect(0,0,100,height);

context.fillRect(400,0,100,height);

interval = setTimeout("intervalSlide()", 20);

}

);

function drawFrame(){

context.clearRect(0,0,canvas.width,canvas.height);

//调用beginPath()确保不会接着上次绘制的图形绘制

context.beginPath();

context.drawImage(currentImage.imgObj,currentImage.x,currentImage.y,width,height);

context.drawImage(currentImage.preImage.imgObj,currentImage.preImage.x,currentImage.preImage.y,width,height);

context.drawImage(currentImage.nextImage.imgObj,currentImage.nextImage.x,currentImage.nextImage.y,width,height);

context.drawImage(currentImage.preImage.preImage.imgObj,currentImage.preImage.preImage.x,currentImage.preImage.preImage.y,width,height);

//遮罩

context.fillStyle="rgba(100,150,185,0.5)";

context.fillRect(0,0,100,height);

context.fillRect(400,0,100,height);

//每一帧的位置变动

currentImage.x -= speed;

currentImage.preImage.x -= speed;

currentImage.nextImage.x -= speed;

currentImage.preImage.preImage.x -= speed;

if(currentImage.x == 200){

currentImage.nextImage.x = 500;

}

//到达指定位置停止变动

if(currentImage.x != stopX){

autoTimeout = setTimeout("drawFrame()",timeoutInterval);

}

else{

}

}

function InitImages(){

img1 = new slideImage("img1",-200,0,document.getElementById("img1"));

img2 = new slideImage("img2",100,0,document.getElementById("img2"));

img3 = new slideImage("img3",400,0,document.getElementById("img3"));

img4 = new slideImage("img4",700,0,document.getElementById("img4"));

img1.preImage = img4;

img1.nextImage = img2;

img2.preImage= img1;

img2.nextImage= img3;

img3.preImage=img2;

img3.nextImage=img4;

img4.preImage = img3;

img4.nextImage = img1;

currentImage=img2;

hilightSelectedImg();

}

function canvasClick(){

currentImage = currentImage.nextImage;

manuTimeout = setTimeout("drawFrame()",timeoutInterval);

}

function intervalSlide(){

currentImage = currentImage.nextImage;

hilightSelectedImg();

autoTimeout = setTimeout("drawFrame()", timeoutInterval);

setTimeout("intervalSlide()", 5000)

}

function iconClick(obj){

if(obj == "img1"){

currentImage = img1;

}

else if(obj == "img2"){

currentImage = img2;

}

else if(obj == "img3"){

currentImage = img3;

}

else if(obj == "img4"){

currentImage = img4;

}

currentImage.preImage.x = 100;

currentImage.preImage.preImage.x = -200;

currentImage.x = 400;

hilightSelectedImg();

manuTimeout = setTimeout("drawFrame()",timeoutInterval);

}

function hilightSelectedImg(){

img1.imgObj.width = 125;

img1.imgObj.height = 150;

img1.imgObj.style.opacity = 0.5;

img2.imgObj.width = 125;

img2.imgObj.height = 150;

img2.imgObj.style.opacity = 0.5;

img3.imgObj.width = 125;

img3.imgObj.height = 150;

img3.imgObj.style.opacity = 0.5;

img4.imgObj.width = 125;

img4.imgObj.height = 150;

img4.imgObj.style.opacity = 0.5

currentImage.imgObj.width = 150;

currentImage.imgObj.height = 175;

currentImage.imgObj.style.opacity = 1;

}

三. css文件。style.css

[css] view

plaincopy

canvas {

border:1px dashed black;

}

.imgGallery{

width:550px;

position:absolute;

height:170px

}

img{

opacity:0.5;

}

怎样canvas画布上添加滚动条,显示更多数据

canvas是不能添加滚动条,

可以把canvas画布放在一个层里,再给这个层添加滚动条,

div style="width:300px; height:200px; overflow:auto"

canvas id="idline" width="750" height="400" style="border:2px solid gray"/canvas

/div

HTML5 在CANVAS标签里面增加滚动条

使用缓存Canvas,将中间的部分缓存,然后drawImage将缓存canvas画到主画布上,这样你可以使用drawImage的剪切方法来模拟滚动了。

js和canvas实现数字滚动,canvas 滚动条

本文目录一览: 1、Unity3d如何实现滚动文本框 2、如何实现canvas的图片轮播 3、怎样canvas画布上添加滚动条,显示更多数据 4、HTML5 在CANVAS标签里面增加滚动条 Unit

2023-12-08
canvas内部滚动条,canvas内容滚动

2022-11-29
canvas图片在路线上滚动,canvas滑动事件

2022-11-25
scroll.js—高效的滚动条组件

2023-05-20
关于createjs旋转滚动的信息

2022-11-23
js找那个canvas超出高度如何自动滚动渲染,js获取页面

2022-11-23
不用java的垂直滚动看板(不用java的垂直滚动看板怎么用

2022-11-15
用Python实现横向滚动

2023-05-13
Python Scrollbar - 实现文本/图像超出边界

2023-05-13
优化用户体验,实现界面滚动--Python Scroolba

2023-05-13
JS控制滚动条滚动全攻略

2023-05-17
web中js时间滚动(js页面滚动)

本文目录一览: 1、JS实现滚动条触底加载更多 2、java web项目中js怎么取到div中滚动条的高度? 3、js如何控制整个页面滚动条的位置 4、web自动化中页面多个滚动条时的拖动操作? 5、

2023-12-08
js网页自动滚动,html 自动滚动

本文目录一览: 1、请教JS高手,怎么让Iframe中的页面自动滚屏 2、js怎么控制网页滚动到指定位置 3、fullpage.js自动滚动怎么设置 4、js控制页面滚动(实例) 请教JS高手,怎么让

2023-12-08
新闻滚动js代码(web滚动代码)

本文目录一览: 1、js如何实现新闻轮播 2、我想要一种新闻滚动的效果,用js实现的 3、js循环倒计时代码 每5秒循环倒计时到0 再从5秒开始 到0之后刷新页面 类似网易的滚动新闻 4、PHP,想实

2023-12-08
Python Anchor and Canvas: 让你的网

2023-05-13
Python实现网页滚动条

2023-05-12
js的canvas应用,canvas web

本文目录一览: 1、JS之使用Canvas绘图 2、《JS原理、方法与实践》- canvas作图(六)- 坐标操作 3、Canvas 使用指南 4、JS中canvas画布绘制中如何实现缩放,位移,旋转

2023-12-08
一段js滚动代码,html一段文字上下滚动代码

本文目录一览: 1、js 滚动代码请教 2、求修改一段js滚动代码,要求平滑滚动,无闪烁 3、文字滚动js代码 4、一段JS代码,自动滚动的,求高手解释一下 js 滚动代码请教 在百度或谷歌搜素“ja

2023-12-08
canvas结合js画字(canvas写字)

本文目录一览: 1、js+html5实现canvas绘制镂空字体文本的方法 2、JS之使用Canvas绘图 3、如何在canvas 画图加文字 4、canvas绘制 js+html5实现canvas绘

2023-12-08
求js实现图片不间断滚动代码,求js实现图片不间断滚动代码的

2022-11-25