富贵资源网 Design By www.hznty.com

本文实例讲述了js用拖动滑块来控制图片大小的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv=Content-Type content="text/html;charset=gb2312">
<title>js拖动滑块控制图片显示大小</title>
<style>
*{margin:0;padding:0;font-size:12px;}
.btn{width:50px;height:15px;cursor:pointer;}
#picViewPanel{margin:5 50 0 50px; width:328px; height:248px;overflow:auto;text-align:center;border:solid 1px #cccccc;}
#slider{margin:0 50px;height:15px;width:328px;border:1px solid #000000;position:relative;}
#sliderLeft{height:13px; width:13px;float:left;border:1px solid #cccccc;cursor:pointer;}
#sliderBlock{height:13px;width:50px;border:1px solid #cccccc;position:absolute;top:0;left:113px;cursor:pointer;background:#cccccc;text-align:center;}
#sliderRight{height:13px;width:13px;float:right;border:1px solid #cccccc;cursor:pointer;}
</style>
</head>
<body>
<div id="picViewPanel"></div>
<div id="slider">
<span id="sliderLeft" ><<</span>
<span id="sliderRight"></span>
<span id="sliderBlock">==</span>
</div>
</body>
<script>
//golbal
var pv = null;
var sd = null;
window.onload=function(){
pv = new PicView("/images/m01.jpg");
sd = new Slider(
function(p){
document.getElementById("sliderBlock").innerHTML = 2*p +"%";
pv.expand(2*p/100);
},function(){});
}
var PicView = function(url,alt){
this.url=url;
this.obj=null;
this.alt=alt"";
this.realWidth=null;
this.realHeight=null;
this.zoom=1;
this.init();
}
PicView.prototype.init=function(){
var _img=document.createElement("img");
_img.src = this.url;
_img.alt = this.alt;
_img.style.zoom = this.zoom;
document.getElementById("picViewPanel").appendChild(_img);
this.obj=_img;
this.realWidth=_img.offsetWidth;
this.realHeight=_img.offsetHeight;
}
PicView.prototype.reBind=function(){
this.obj.style.width =  this.realWidth*this.zoom+"px";
this.obj.style.height = this.realHeight*this.zoom+"px";
//this.obj.style.zoom = this.zoom;
}
PicView.prototype.expand=function(n){
this.zoom=n;
this.reBind();
}
var Slider = function(ing,ed){
this.block=document.getElementById("sliderBlock");
this.percent = 0;
this.value = 0;
this.ing = ing;
this.ed = ed;
this.init();
}
Slider.prototype.init=function(){
var _sx=0;
var _cx=0;
var o=this.block;
var me=this;
o.onmousedown=function(e){
var e=window.event||e;
_sx = o.offsetLeft;
_cx = e.clientX-_sx;
document.body.onmousemove=move;
document.body.onmouseup=up;
};
function move(e){
var e=window.event||e;
var pos_x = e.clientX - _cx;
pos_x=pos_x<13"px";
me.percent=(pos_x-13)/2;
me.ing(me.percent);
}
function up(){
document.body.onmousemove=function(){};
document.body.onmouseup=function(){};
}
}
</script>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。