地图上面的搜索框要可拖拽
但是搜索框是有点击事件的,点击显隐下拉菜单,如果拖拽的事件源选择select框的话,会有样式(十字拖动符cursor:move与selelt默认点击的箭头)冲突
思索良久,就用外边距区域做事件源啊,废话不多,看代码。。。。
1、html页面放置的select搜索框(注意看哦,重点是h6标签哦)

==请选择==
1
2

2、以下是样式
#searchbox {
border:1px solid #fff;
position:absolute;
left:50px;
top:50px;
}
#searchbox select{
width:350px;
height: 40px;
}
#searchbox h6.search-top {
position:absolute;
top:-6px;
left:0;
width:100%;
height:6px;
line-height:6px;
color:white;
cursor:move;
}
#searchbox h6.search-bottom {
position:absolute;
bottom:-6px;
left:0;
width:100%;
height:6px;
line-height:6px;
color:white;
cursor:move;
}
#searchbox h6.search-left {
position:absolute;
bottom:0;
left:-6px;
width:6px;
height:100%;
color:white;
cursor:move;
}
#searchbox h6.search-right {
position:absolute;
bottom:0;
right:-6px;
width:6px;
height:100%;
color:white;
cursor:move;
}
3、以下是js方法哦(方法有参考某个童鞋的,时间久忘记名字了,此处不明示了,理解一下哦)
function drag(obj) {
if (typeof obj === 'string') {
var obj = document.getElementById(obj);
} else {
var obj = obj;
}
function fixEvent(event) {
event.target = event.srcElement;
event.preventDefault = fixEvent.preventDefault;
return event;
}
fixEvent.preventDefault = function () {
this.returnValue = false;
};
obj.onmousedown = mousedown;
function mousedown(e) {
var e = e || fixEvent(window.event);
var disX = e.clientX - obj.offsetLeft;
var disY = e.clientY - obj.offsetTop;
if (e.target.tagName === 'H6') {
document.onmousemove = move;
document.onmouseup = up;
} else {
document.onmousemove = null;
document.onmouseup = null;
}
function move(e) {
var e = e || fixEvent(window.event);
var left = e.clientX - disX;
var top = e.clientY - disY;
if (obj.setCapture) {
obj.setCapture();
}
if (left < 0) {
left = 0;
} else if (left > document.documentElement.clientWidth - obj.offsetWidth) {
left = document.documentElement.clientWidth - obj.offsetWidth;
}
if (top < 0) {
top = 0;
} else if (top > document.documentElement.clientHeight - obj.offsetHeight) {
top = document.documentElement.clientHeight - obj.offsetHeight;
}
obj.style.left = left + 'px';
obj.style.top = top + 'px';
return false;
};
function up() {
if (obj.releaseCapture) {
obj.releaseCapture();
}
document.onmousemove = null;
document.onmouseup = null;
}
};
}
4、然后是js页面调用方法
window.onload = function () {
var trigger = document.getElementById('searchbox');
drag(trigger);
};
综上:此拖拽事件已搞定,如有问题留言探讨,转载请注明出处。

最新文章

  1. 用Fmx调用Bass.dll
  2. Sql数据库帮组类
  3. iOS开发之UIImage等比缩放
  4. 分布式消息队列的使用kakfa
  5. mysql 分区信息查看
  6. 新手笔记-tftp与yum
  7. Android Tombstone/Crash的log分析和定位
  8. SQL 和 .NET Framework 数据类型对应表
  9. Hive总结(七)Hive四种数据导入方式
  10. 介绍一种很棒的wince 如何替换系统声音的方法
  11. css 浮动问题 display显示 和 光标设置cursor
  12. kettle实现多表同步
  13. python os.path.join()
  14. app和bootloader跳转 MSP与PSP
  15. Linux运维之--LVS、Nginx、HAproxy有什么区别?
  16. [转发]jquery获取当前页面的URL信息
  17. [Arch] 03. Practice UML in project
  18. iframs刷新的两种方法
  19. C++飞机大战
  20. grep匹配字符串出现的次数

热门文章

  1. IdentityServer4 学习笔记[2]-用户名密码验证
  2. linux网络编程中的基本概念
  3. 牛客寒假算法基础集训营4 B applese 走方格
  4. kuangbin专题十六 KMP&amp;&amp;扩展KMP HDU3347 String Problem(最小最大表示法+kmp)
  5. Qt 学习之路 2(20):event()
  6. [PowerShell]template engine
  7. redis修改密码和更改端口
  8. CodeForces-Zuhair and Strings(思维+枚举)
  9. 09-排序3 Insertion or Heap Sort (25 分)
  10. 设置Linux shell超时自动退出