帮助中心
获取牛币
联系我们
关于我们
版权声明
素材牛首页
微博登录
QQ登录
微信扫码登录
注册
登录
新浪微博
QQ登陆
微信登录
热门搜索:
小程序
支付
Java
后台模板
上传
商城模板
jQuery
手机
Thinkphp
微信
Vue.js
首 页
网页特效
整站源码
PHP实例
网站模版
工具箱
常用代码
论坛
游戏源码
资源分享
当前位置:
首页
»
精选常用代码
» 导航栏拖拽沿边停靠效果
导航栏拖拽沿边停靠效果
浏览:654次
-
评论:2次
-
发布时间:2017-07-25
Html
Css
Js
导航一
导航二
导航三
导航四
导航五
* { margin:0; padding:0; font-family:"微软雅黑"; } .nav { position:fixed; z-index:999; overflow:hidden; } .shpere { height:50px; width:50px; border-radius:50%; border:5px double #000; } .top,.bottom { width:100%; height:50px; left:0; } .top { top:0; box-shadow:0 3px 3px #ccc; } .bottom { bottom:0; box-shadow:0 -3px 3px #ccc; } .left,.right { height:100%; width:100px; top:0; } .left { left:0; box-shadow:3px 0 3px #ccc; } .right { right:0; box-shadow:-3px 0 3px #ccc; } .nav a { display:block; float:left; width:100px; height:50px; color:#000; text-decoration:none; text-align:center; line-height:50px; } .nav span { display:block; float:left; width:50px; height:50px; text-align:center; padding-top:9px; } a:hover { background:rgba(128,128,128,0.8); } .dir { position:fixed; top:50%; width:100%; z-index:0; } .dir span { position:absolute; width:80px; height:80px; background:#eee; box-shadow:3px 3px 3px #bbb inset; left:50%; transform-origin:0% 0%; border-radius:10px; }
var oNav = document.getElementsByClassName('nav')[0]; var oS = oNav.getElementsByTagName('span')[0]; var h = window.innerHeight; var w = window.innerWidth; var classStr; oS.onmousedown = function(e) { classStr = oNav.className; var e = e || window.event; let x = e.clientX; let y = e.clientY; oNav.style.left = x - 25 + 'px' oNav.style.top = y - 25 + 'px'; oNav.className = 'nav shpere'; this.onmousemove = function(e) { let x = e.clientX; let y = e.clientY; oNav.style.left = x - 25 + 'px' oNav.style.top = y - 25 + 'px'; oNav.style.top = y - 25 + 'px'; } this.onmouseleave = blur2; } var blur1 = function() { oS.onmouseleave = null; var top = oNav.offsetTop + 25; var bottom = h - top; var left = oNav.offsetLeft + 25; var right = w - left; var s = [top, bottom, left, right]; Switch(minOrd(s)); } function minOrd(s = []) { var ord = 0; var min = s[0]; for (var i = 1; i < s.length; i++) { if (min > s[i]) { ord = i; min = s[i]; } } return ord; } var blur2 = function() { var s; switch (classStr) { case "nav top": s = 0; break; case "nav bottom": s = 1; break; case "nav left": s = 2; break; case "nav right": s = 3; break; } Switch(s); } function Switch(result) { switch (result) { case 0: { oNav.style.top = 0; oNav.style.left = 0; oNav.style.bottom = 'auto'; oNav.style.right = 'auto'; oNav.className = 'nav top'; }; break; case 1: { oNav.style.bottom = 0; oNav.style.left = 0; oNav.style.top = 'auto'; oNav.style.right = 'auto'; oNav.className = 'nav bottom'; }; break; case 2: { oNav.style.left = 0; oNav.style.top = 0; oNav.style.right = 'auto'; oNav.style.bottom = 'auto'; oNav.className = 'nav left'; }; break; case 3: { oNav.style.right = 0; oNav.style.top = 0; oNav.style.left = 'auto'; oNav.style.bottom = 'auto'; oNav.className = 'nav right'; }; break; } oS.onmousemove = null; } oS.onmouseup = blur1;
↑上面代码改变,会自动显示代码结果
jQuery调用版本:
1.11.3
<!doctype html><html><head><meta charset="utf-8"><title>导航栏拖拽沿边停靠效果-www.sucainiu.com</title><script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script><style>
</style></head><body>
<script>
</script>
</body></html>
立即下载
收藏
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!
充值积分
充值会员
更多说明»
代码描述:可拖拽导航栏,点击图标拖拽到您想停放的位置
商品列表展示效果
纯CSS表头固定
讨论这个常用代码(2)
回答他人问题或分享心得会奖励牛币
Lv3 码奴
ct***05
2017年08月01日
拖拽的吗?怎么看不出什么效果啊,拖拽没有反应啊,和浏览器兼容有关吗
素***员
:应该是你拖错地方了,应该点击那个"X"进行拖拽
回复
文明上网,理性发言! 😉 阿里云幸运券,
戳我领取
发表评论
提交回复
我的积分余额:
0
已下载次数:
654
所需牛币:
5
开始下载
牛币获取:
签到、评论、充值
» 在线充值
(10牛币=1元)
成为VIP可永久免积分下载全部常用代码
» 查看详情
VIP
客服
签到
充值