图片移动组件

支持图片移动,即左右上下移动,DEMO

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片移动</title>
<link rel="stylesheet" type="text/css" href="css/imgCss.css">
</head>
<body style="background-color:#BFC9DA">
<div style="margin:50px auto;width:500px;height:500px">
<div style="font-size:24px;color:red;padding: 10px 150px;">图片移动组件</div>
<div style="margin:10px"><input type="text" id="picNumber" name="picNumber" value="1" style="width:40px"/><button type="button" onclick="addPic();">上传图片</button></div>
<div id="prodImg"></div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var imgArray = ["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg","img/6.jpg","img/7.jpg"];
function init(){
movePic.init();
}
function addPic(){
var array = ["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg","img/6.jpg","img/7.jpg","img/8.jpg","img/9.jpg","img/10.jpg"];
var number = parseInt($(‘#picNumber‘).val());
var imgLength=imgArray.length;
if((imgLength+number)>8){
alert("最多只能上传八张图片!");
return ;
}
for(var i = 0;i<number;i++){
imgArray.push(array[Math.floor(Math.random()*10)]);
}
imgLength = imgArray.length;
movePic.init();
}

var movePic={
init:function(){
var imgHtml = [],imgLength = imgArray.length;
for(var i=0;i<imgLength;i++){
var operateHtml = [];
operateHtml.push(‘<div class="prodImg" id="prodImg‘+(i+1)+‘"><img id="img‘+(i+1)+‘" class="imgcss"><div class="operate" id="operate‘+(i+1)+‘">‘);
operateHtml.push(‘<span class="toleft" id="toleft‘+(i+1)+‘">左移</span>‘);
if(i<4){
operateHtml.push(‘<span class="todown" id="todown‘+(i+1)+‘">下移</span>‘);
}else{
operateHtml.push(‘<span class="toup" id="toup‘+(i+1)+‘">上移</span>‘);
}
operateHtml.push(‘<span class="toright"id="toright‘+(i+1)+‘">右移</span>‘);
operateHtml.push(‘<span class="del" id="del‘+(i+1)+‘">删除</span>‘);
operateHtml.push(‘</div></div>‘);
imgHtml.push(operateHtml.join(‘‘));
}

var prodImgHtml = [];
prodImgHtml.push(‘<div style="width:480px;margin:5px;">‘);
for(var i=0;i<imgLength;i++){
prodImgHtml.push(imgHtml[i]);
if(i==3){
prodImgHtml.push(‘</div><div style="width:480px;margin:5px;">‘);
}
}
$(‘#prodImg‘).html(prodImgHtml.join(‘‘));

$(‘#toleft1‘).hide();$(‘#toleft5‘).hide();
$(‘#toright4‘).hide();$(‘#toright8‘).hide();

for(var i=0;i<imgLength;i++){
$(‘#todown‘+(i+1)).hide();$(‘#toright‘+(i+1)).hide();
$(‘#todown‘+(i-3)).show();if(i!=0&&i!=4){$(‘#toright‘+i).show();}
}

for(var i=0;i<imgLength;i++){
$(‘#img‘+(i+1)).attr("src",imgArray[i]);
this.bindImg(i+1);this.bindLeft(i);
this.bindRight(i);this.bindDel(i);
}
for(var i=0;i<4;i++){
this.bindDown(i);this.bindUp(i);
}
},
bindImg:function(i){$(‘#prodImg‘+i).mouseenter(function(){$(‘#operate‘+i).show();});$(‘#prodImg‘+i).mouseleave(function(){$(‘#operate‘+i).hide()})},
bindLeft:function(i){$(‘#toleft‘+(i+2)).click(function(){movePic.changeArray(i)})},
bindDown:function(i){$(‘#todown‘+(i+1)).click(function(){movePic.downArray(i+1)})},
bindRight:function(i){$(‘#toright‘+(i+1)).click(function(){movePic.changeArray(i)})},
bindUp:function(i){$(‘#toup‘+(i+5)).click(function(){upArray(i+5)})},
bindDel:function(i){$(‘#del‘+(i+1)).click(function(){delArray(i+1)})},
changeArray:function(num){var temp = imgArray[num];imgArray[num] = imgArray[num+1];imgArray[num+1] = temp;this.init()},
downArray:function(num){
var newImgArray = [];
var delImg = imgArray[num-1];
imgArray.splice(num-1,1);
for(var i = 0;i<imgArray.length;i++){
newImgArray.push(imgArray[i]);
if(i==num+2){
newImgArray.push(delImg);
}

}
imgArray = newImgArray;
this.init();
},
upArray:function(num){
var newImgArray = [];
var delImg = imgArray[num-1];
imgArray.splice(num-1,1);
for(var i = 0;i<imgArray.length;i++){
if(i==num-5){
newImgArray.push(delImg);
}
newImgArray.push(imgArray[i]);
}
imgArray = newImgArray;
imgLength = imgArray.length;
this.init();
},
delArray:function(num){
imgArray.splice(num-1,1);
imgLength = imgArray.length;
this.init();
}
}
</script>

</body>
</html>

  

图片移动组件,布布扣,bubuko.com

时间: 2024-08-28 14:47:44

图片移动组件的相关文章

6.安装和配置OpenStack图片服务组件

安装和配置图片服务组件 这里是安装在控制器上 安装和配置图片服务组件 yum install –y openstack-glance python-glanceclient 编辑/etc/glance/glance-api.conf mv /etc/glance/glance-api.conf /etc/glance/glance-api.conf_bak vim /etc/glance/glance-api.conf [database] connection = mysql://glance

图片拖动组件

图片拖动组件 DEMO <html> <HEAD> <title>鼠标拖动图片</title> <style type="text/css"> .dragme{position:absolute; cursor:move;width:110px;height:110px;border:#ececec 2px solid;} .imgcss{width:110px;height:110px;} .close{position:a

从零开始学android&lt;ImageSwitcher图片切换组件.二十六.&gt;

ImageSwitcher组件的主要功能是完成图片的切换显示,例如用户在进行图片浏览的时候,可以通过按钮点击一张张的切换显示的图片,而且使用ImageSwitcher组件在每次切换的时候也可以为其增加一些动画的效果,此类定义如下: java.lang.Object ? android.view.View ? android.view.ViewGroup ? android.widget.FrameLayout ? android.widget.ViewAnimator ? android.wid

Android图片管理组件(双缓存+异步加载)

转自:http://www.oschina.net/code/snippet_219356_18887?p=3#comments ImageManager2这个类具有异步从网络下载图片,从sd读取本地图片,内存缓存,硬盘缓存,图片使用动画渐现等功能,已经将其应用在包含大量图片的应用中一年多,没有出现oom Android程序常常会内存溢出,网上也有很多解决方案,如软引用,手动调用recycle等等.但经过我们实践发现这些方案,都没能起到很好的效果,我们的应用依然会出现很多oom,尤其我们的应用包

ReactNative学习-滑动查看图片第三方组件react-native-swiper

滑动查看图片第三方组件:react-native-swiper,现在的版本为:1.4.3,该版本还不支持Android. 下面介绍的是该组件的一些用法,可能总结的不完整,希望大家一起来共同完善. 官方文档:https://github.com/leecade/react-native-swiper 效果图: 安装 npm install --save react-native-swiper 基础用法 import React, {AppRegistry,Component,StyleSheet,

Vue图片浏览组件v-viewer,支持旋转、缩放、翻转等操作

v-viewer 用于图片浏览的Vue组件,支持旋转.缩放.翻转等操作,基于viewer.js. 从0.x迁移 你需要做的唯一改动就是手动引入样式文件: 1 import 'viewerjs/dist/viewer.css' 安装 使用npm命令安装 1 npm install v-viewer 使用 引入v-viewer及必需的css样式,并使用Vue.use()注册插件,之后即可使用. 12345678910111213141516171819202122232425 <template>

ReactNative: 使用图片裁剪组件ImageEditor组件

一.简介 图片在应用中的使用非常常见,绚丽的图片能使App增色不少.当设计师给开发者一张图片后,有时根据情况需要用到该图片中的某一部分,当然研发可以让设计师再设计一张,其实,还有其他的办法可以实现,例如绘制指定局域的图片.裁剪图片等.在ReactNative中,提供了图片裁剪组件ImageEditor,这个组件可以将一张图片进行任意的裁剪,获取需要的那一部分.ImageEditor组件的API相当简单,仅仅提供了一个静态方法,下面就来研究一下. 二.API 提供的裁剪图片的静态方法如下: //u

从零開始学android&amp;lt;ImageSwitcher图片切换组件.二十六.&amp;gt;

ImageSwitcher组件的主要功能是完毕图片的切换显示,比如用户在进行图片浏览的时候.能够通过button点击一张张的切换显示的图片,并且使用ImageSwitcher组件在每次切换的时候也能够为其添加一些动画的效果,此类定义例如以下: java.lang.Object ? android.view.View ? android.view.ViewGroup ? android.widget.FrameLayout ? android.widget.ViewAnimator ? andro

iOS开发之窥探UICollectionViewController(五) --一款炫酷的图片浏览组件

本篇博客应该算的上CollectionView的高级应用了,从iOS开发之窥探UICollectionViewController(一)到今天的(五),可谓是由浅入深的窥探了一下UICollectionView的用法,这些用法不仅包括SDK中自带的流式布局(UICollectionViewDelegateFlowLayout)而且介绍了如何根据你的需求去自定义属于你自己的CollectionView.自定义的CollectionView可谓是非常灵活,其灵活性也决定了其功能的强大.Collect