请选择 进入手机版 | 继续访问电脑版

 找回密码
 注册

只需一步,快速开始

蓝色理想 最新研发动态 用悬赏 三天解决问题 测测你的龙年运势 地图任务一定要做 - 给官方提建议

论坛活动及任务 归纳网站最新活动 地图和邮件任务 程序员MM蒸男盆友,坐标魔都

《众妙之门2》强势来袭,试读赢图书! 想加薪?!蓝色理想招聘提供你更多机会 悬赏答疑,赚取积分兑奖品!

楼主: yaohaixiao

【原创】滑动门导航类,多种好看且实用的示例,一定来看看!(8月1日更新) [复制链接]

神仙撮撮

中级会员

帖子
131
体力
479
威望
0
居住地
广东省 广州市
发表于 2009-9-10 10:07:23 |显示全部楼层
真不错,谢谢了,已收藏!
帖子
74
体力
414
威望
0
居住地
广东省 深圳市
发表于 2009-9-10 13:37:58 |显示全部楼层
收藏了
中间
帖子
251
体力
1115
威望
0
居住地
辽宁省 盘锦市
发表于 2009-9-10 15:44:42 |显示全部楼层
太强悍啦。。
帖子
8
体力
39
威望
0
居住地
山东省 威海市
发表于 2009-9-10 16:11:09 |显示全部楼层
不错不错。。收藏了

深白se

中级会员  

帖子
138
体力
435
威望
2
居住地
广东省 惠州市
发表于 2009-9-14 11:33:22 |显示全部楼层
嘻嘻..好东西 .~`我做 个笔记 .我回来再慢慢研究 .~
http://www.cnblogs.com/jesktop/

小真子

银牌会员

帖子
586
体力
1794
威望
6
居住地
湖北省 武汉市
发表于 2009-9-14 14:18:59 |显示全部楼层
收藏了,在这里做个记号,下次来下
个人网站:设计源
帖子
201
体力
895
威望
0
发表于 2009-9-18 09:32:38 |显示全部楼层

在firefox下不执行

姚大侠能否帮忙看一下,自己研究用。小可做设计出身,js比较若......

 提示:您可以先修改部分代码再运行

帖子
201
体力
895
威望
0
发表于 2009-9-18 09:36:04 |显示全部楼层

静态的就可以

研究用途,看了姚大侠的代码。我才真正了解了什么要重构,而不是为了框架而堆砌。关于绝对定位和dl dd的列表有空的时候还望多指教!先行谢过!
yaohaixiao 楼主

会武术的科学家

实习版主

帖子
2057
体力
5636
威望
45
居住地
浙江省 杭州市
发表于 2009-9-18 12:11:46 |显示全部楼层

回复 250# childmenu 的帖子

我写了例子,你自己看看,没有改你的代码,因为比较乱,把JS和HTML,CSS混杂在一起,不推荐这么做,看看我的DEMO吧:

 提示:您可以先修改部分代码再运行


  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>划过显示大图</title>
  6. <style type="text/css">
  7. *{margin:0;padding:0;}
  8. body{background:#FFF;color:#000;text-align:center;font:normal 12px Georgia, Arial, Helvetica, sans-serif;}
  9. a:link,a:visited{color:#369;text-decoration:underline;}
  10. a:hover{color:#C80000;text-decoration:none;}
  11. span,li,dt,dd,p,h1,h2,h3,h4,h5,h6{text-align:left;}
  12. img{border:0;}
  13. ul,li{list-style-type:none;}
  14. p{padding:5px 0;line-height:150%;}

  15. h1{margin:0 auto;width:100%;background:#353535 url(http://www.yaohaixiao.com/effects/img/logo.png) 0 0 no-repeat;font-size:28px;height:60px;color:#FFF;line-height:60px;text-indent:60px;overflow:hidden;border-bottom:3px solid #999;}
  16. #container{margin:20px auto;width:625px;overflow:hidden;border:1px solid #999;padding:5px;}

  17. #samples{float:left;width:100%;overflow:hidden;}
  18. #samples li{float:left;width:115px;margin:5px;display:inline;overflow:hidden;}
  19. #samples li img{width:115px;height:50px;}
  20. #samples li p{margin:0 auto;padding:0;line-height:26px;width:100%;text-align:center;font-size:12px;height:26px;overflow:hidden;}

  21. #overlayer{position:absolute;z-index:200;width:460px;height:200px;padding:3px;border:2px solid #999;background-color:#FFF;}
  22. #overlayer img{width:460px;height:200px;}

  23. #footer{margin:0 auto;width:960px;padding:15px 0;overflow:hidden;border-top:1px solid #999;}
  24. #footer p{margin:0 auto;width:960px;line-height:20px;font-family:Georgia,sans-serif;text-align:center;font-size:14px;}
  25. </style>
  26. </head>
  27. <body>
  28. <h1>划过显示大图</h1>
  29. <div id="container">
  30.          <ul id="samples">
  31.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/1.jpg" title="图片(1)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/1.jpg" alt="图片(1)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/1.jpg">图片(1)</a></p></li>
  32.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/2.jpg" title="图片(2)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/2.jpg" alt="图片(2)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/2.jpg">图片(2)</a></p></li>
  33.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/3.jpg" title="图片(3)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/3.jpg" alt="图片(3)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/3.jpg">图片(3)</a></p></li>
  34.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/4.jpg" title="图片(4)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/4.jpg" alt="图片(4)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/4.jpg">图片(4)</a></p></li>
  35.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/5.jpg" title="图片(5)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/5.jpg" alt="图片(5)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/5.jpg">图片(5)</a></p></li>
  36.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/6.jpg" title="图片(6)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/6.jpg" alt="图片(6)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/6.jpg">图片(6)</a></p></li>
  37.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/7.jpg" title="图片(7)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/7.jpg" alt="图片(7)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/7.jpg">图片(7)</a></p></li>
  38.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/8.jpg" title="图片(8)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/8.jpg" alt="图片(8)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/8.jpg">图片(8)</a></p></li>
  39.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/9.jpg" title="图片(9)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/9.jpg" alt="图片(9)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/9.jpg">图片(9)</a></p></li>
  40.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/10.jpg" title="图片(10)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/10.jpg" alt="图片(10)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/10.jpg">图片(10)</a></p></li>
  41.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/1.jpg" title="图片(11)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/1.jpg" alt="图片(11)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/1.jpg">图片(11)</a></p></li>
  42.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/2.jpg" title="图片(12)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/2.jpg" alt="图片(12)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/2.jpg">图片(12)</a></p></li>
  43.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/3.jpg" title="图片(13)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/3.jpg" alt="图片(13)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/3.jpg">图片(13)</a></p></li>
  44.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/4.jpg" title="图片(14)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/4.jpg" alt="图片(14)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/4.jpg">图片(14)</a></p></li>
  45.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/5.jpg" title="图片(15)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/5.jpg" alt="图片(15)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/5.jpg">图片(15)</a></p></li>
  46.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/6.jpg" title="图片(16)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/6.jpg" alt="图片(16)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/6.jpg">图片(16)</a></p></li>
  47.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/7.jpg" title="图片(17)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/7.jpg" alt="图片(17)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/7.jpg">图片(17)</a></p></li>
  48.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/8.jpg" title="图片(18)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/8.jpg" alt="图片(18)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/8.jpg">图片(18)</a></p></li>
  49.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/9.jpg" title="图片(19)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/9.jpg" alt="图片(19)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/9.jpg">图片(19)</a></p></li>
  50.                   <li><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/10.jpg" title="图片(20)"><img src="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/10.jpg" alt="图片(20)" /></a><p><a href="http://www.yaohaixiao.com/effects/samples/newscarousel/samples/10.jpg">图片(20)</a></p></li>
  51.          </ul>
  52. </div>
  53. <div id="footer"><p>Copyright © 2008-2009 <a href="http://www.yaohaixiao.com/">yaohaixiao.com</a>, All right reserved.</p></div>
  54. <script type="text/javascript">
  55. <!--
  56. (function(){
  57.         var D = document, Container = D.getElementById('samples'), Samples = Container.getElementsByTagName('img'), i, len = Samples.length, Overlayer = null;
  58.         var ua = navigator.userAgent.toLowerCase(), isOpera = (ua.indexOf('opera') > -1), isIE = (!isOpera && ua.indexOf('msie') > -1), getViewportWidth = function(){// 获得窗口可视区域宽度
  59.                 var j = self.innerWidth;
  60.                 var k = D.compatMode;
  61.                 if (k || isIE) {
  62.                         j = (k == "CSS1Compat") ? D.documentElement.clientWidth : D.body.clientWidth;
  63.                 }
  64.                 return j;
  65.         }, getViewportHeight = function(){// 获得窗口可视区域高度
  66.                 var j = self.innerHeight;
  67.                 var k = D.compatMode;
  68.                 if ((k || isIE) && !isOpera) {
  69.                         j = (k == "CSS1Compat") ? D.documentElement.clientHeight : D.body.clientHeight;
  70.                 }
  71.                 return j;
  72.         }, getPageX = function(el){// 获得元素(节点)在页面中的X坐标
  73.                 var box = null, parentNode = null, left = 0;
  74.                 if (el.getBoundingClientRect) {
  75.                         box = el.getBoundingClientRect();
  76.                         left = box.left + Math.max(D.documentElement.scrollLeft, D.body.scrollLeft);
  77.                 }
  78.                 else {
  79.                         left = el.offsetLeft;
  80.                         parentNode = el.offsetParent;
  81.                         if (parentNode != el) {
  82.                                 while (parentNode) {
  83.                                         left += parentNode.offsetLeft;
  84.                                         parentNode = parentNode.offsetParent;
  85.                                 }
  86.                         }
  87.                 }
  88.                 return left;
  89.         }, getPageY = function(el){// 获得元素(节点)在页面中的坐标
  90.                 var box = null, parentNode = null, top = 0;
  91.                 if (el.getBoundingClientRect) {
  92.                         box = el.getBoundingClientRect();
  93.                         top = box.top + Math.max(D.documentElement.scrollTop, D.body.scrollTop);
  94.                 }
  95.                 else {
  96.                         top = el.offsetTop;
  97.                         parentNode = el.offsetParent;
  98.                         if (parentNode != el) {
  99.                                 while (parentNode) {
  100.                                         top += parentNode.offsetTop;
  101.                                         parentNode = parentNode.offsetParent;
  102.                                 }
  103.                         }
  104.                 }
  105.                 return top;
  106.         };
  107.         for(i=0;i<len;++i){
  108.                 Samples[i].onmouseover = function(){
  109.                         var imgPath = this.parentNode.href, imgAlt = this.alt, bigImg = '<img src="' + imgPath + '" alt="' + imgAlt + '" />', pageX = getPageX(this), pageY = getPageY(this), viewportWidth = getViewportWidth(), viewportHeight = getViewportHeight(), layerWidth = 0, layerHeight = 0;
  110.                         if (!Overlayer) { // 如果是第一次加载,则创建显示放大图片的遮罩层(overlayer)
  111.                                 Overlayer = D.createElement('div');
  112.                                 Overlayer.id = 'overlayer';
  113.                                 D.body.appendChild(Overlayer);
  114.                         }
  115.                         else { // 如果已经创建了,则直接显示层就可以了
  116.                                 Overlayer.style.display = 'block';
  117.                         }
  118.                         layerWidth = Overlayer.offsetWidth;    // 获得遮罩层的宽度
  119.                         layerHeight = Overlayer.offsetHeight;  // 获得遮罩层的高度
  120.                         // 根据当前小图片的位置,调成遮罩层显示的位置
  121.                         if ((pageX + this.offsetWidth + 5 + layerWidth) > viewportWidth) {
  122.                                 pageX -= 5 + layerWidth;
  123.                         }
  124.                         else {
  125.                                 pageX += this.offsetWidth + 5;
  126.                         }
  127.                         if ((pageY + this.offsetHeight + 5 + layerHeight) > viewportHeight) {
  128.                                 pageY -= 5 + layerHeight;
  129.                         }
  130.                         // 定位遮罩层
  131.                         Overlayer.style.left = pageX + 'px';
  132.                         Overlayer.style.top = pageY + 'px';
  133.                         Overlayer.innerHTML = bigImg;
  134.                 };
  135.                 Samples[i].onmouseout = function(){
  136.                         Overlayer.style.display = 'none';
  137.                         Overlayer.innerHTML = '';
  138.                 };
  139.         }
  140. })();
  141. //-->       
  142. </script>
  143. </body>
  144. </html>
复制代码


示例下载:

[ 本帖最后由 yaohaixiao 于 2009-9-18 12:59 编辑 ]
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
帖子
2958
体力
3689
威望
2
居住地
广东省 深圳市
发表于 2009-9-18 12:27:47 |显示全部楼层
在懒人那找下也很多,lz都把js写在一起,我不知道我们该怎么分离出来用????
yaohaixiao 楼主

会武术的科学家

实习版主

帖子
2057
体力
5636
威望
45
居住地
浙江省 杭州市
发表于 2009-9-18 13:28:51 |显示全部楼层

回复 252# dededesign 的帖子

我稍微组织了下,看看这样的代码,应该比较好理解吧

  1. var YHover = function(){
  2.         var D = document, ua = navigator.userAgent.toLowerCase(), isOpera = (ua.indexOf('opera') > -1), isIE = (!isOpera && ua.indexOf('msie') > -1);

  3.         return {
  4.                 photos: function(container, samples){
  5.                         var Container = D.getElementById(container), Samples = Container.getElementsByTagName(samples), i, len = Samples.length, Overlayer = null, oSelf = this;
  6.                         for (i = 0; i < len; ++i) {
  7.                                 Samples[i].onmouseover = function(){
  8.                                         var imgPath = this.parentNode.href, imgAlt = this.alt, bigImg = '<img src="' + imgPath + '" alt="' + imgAlt + '" />', pageX = oSelf.getPageX(this), pageY = oSelf.getPageY(this), viewportWidth = oSelf.getViewportWidth(), viewportHeight = oSelf.getViewportHeight(), layerWidth = 0, layerHeight = 0;
  9.                                         if (!Overlayer) {
  10.                                                 Overlayer = D.createElement('div');
  11.                                                 Overlayer.id = 'overlayer';
  12.                                                 D.body.appendChild(Overlayer);
  13.                                         }
  14.                                         else {
  15.                                                 Overlayer.style.display = 'block';
  16.                                         }
  17.                                         layerWidth = Overlayer.offsetWidth;
  18.                                         layerHeight = Overlayer.offsetHeight;
  19.                                         if ((pageX + this.offsetWidth + 5 + layerWidth) > viewportWidth) {
  20.                                                 pageX -= 5 + layerWidth;
  21.                                         }
  22.                                         else {
  23.                                                 pageX += this.offsetWidth + 5;
  24.                                         }
  25.                                         if ((pageY + this.offsetHeight + 5 + layerHeight) > viewportHeight) {
  26.                                                 pageY -= 5 + layerHeight;
  27.                                         }
  28.                                         Overlayer.style.left = pageX + 'px';
  29.                                         Overlayer.style.top = pageY + 'px';
  30.                                         Overlayer.innerHTML = bigImg;
  31.                                 };
  32.                                 Samples[i].onmouseout = function(){
  33.                                         Overlayer.style.display = 'none';
  34.                                         Overlayer.innerHTML = '';
  35.                                 };
  36.                         }
  37.                 },
  38.                 getViewportWidth: function(){
  39.                         var j = self.innerWidth;
  40.                         var k = D.compatMode;
  41.                         if (k || isIE) {
  42.                                 j = (k == "CSS1Compat") ? D.documentElement.clientWidth : D.body.clientWidth;
  43.                         }
  44.                         return j;
  45.                 },
  46.                 getViewportHeight: function(){
  47.                         var j = self.innerHeight;
  48.                         var k = D.compatMode;
  49.                         if ((k || isIE) && !isOpera) {
  50.                                 j = (k == "CSS1Compat") ? D.documentElement.clientHeight : D.body.clientHeight;
  51.                         }
  52.                         return j;
  53.                 },
  54.                 getPageX: function(el){
  55.                         var box = null, parentNode = null, left = 0;
  56.                         if (el.getBoundingClientRect) {
  57.                                 box = el.getBoundingClientRect();
  58.                                 left = box.left + Math.max(D.documentElement.scrollLeft, D.body.scrollLeft);
  59.                         }
  60.                         else {
  61.                                 left = el.offsetLeft;
  62.                                 parentNode = el.offsetParent;
  63.                                 if (parentNode != el) {
  64.                                         while (parentNode) {
  65.                                                 left += parentNode.offsetLeft;
  66.                                                 parentNode = parentNode.offsetParent;
  67.                                         }
  68.                                 }
  69.                         }
  70.                         return left;
  71.                 },
  72.                 getPageY: function(el){
  73.                         var box = null, parentNode = null, top = 0;
  74.                         if (el.getBoundingClientRect) {
  75.                                 box = el.getBoundingClientRect();
  76.                                 top = box.top + Math.max(D.documentElement.scrollTop, D.body.scrollTop);
  77.                         }
  78.                         else {
  79.                                 top = el.offsetTop;
  80.                                 parentNode = el.offsetParent;
  81.                                 if (parentNode != el) {
  82.                                         while (parentNode) {
  83.                                                 top += parentNode.offsetTop;
  84.                                                 parentNode = parentNode.offsetParent;
  85.                                         }
  86.                                 }
  87.                         }
  88.                         return top;
  89.                 }
  90.         };
  91. }();
  92. YHover.photos('container','img');
复制代码

 提示:您可以先修改部分代码再运行



在不行,这个我想大家都可以看懂吧:

  1. function YPhotos(container, samples){
  2.         var D = document, Container = D.getElementById(container), Samples = Container.getElementsByTagName(samples), i, len = Samples.length, Overlayer = null, oSelf = this;
  3.         for (i = 0; i < len; ++i) {
  4.                 Samples[i].onmouseover = function(){
  5.                         var imgPath = this.parentNode.href, imgAlt = this.alt, bigImg = '<img src="' + imgPath + '" alt="' + imgAlt + '" />', pageX = oSelf.getPageX(this), pageY = oSelf.getPageY(this), viewportWidth = oSelf.getViewportWidth(), viewportHeight = oSelf.getViewportHeight(), layerWidth = 0, layerHeight = 0;
  6.                         if (!Overlayer) {
  7.                                 Overlayer = D.createElement('div');
  8.                                 Overlayer.id = 'overlayer';
  9.                                 D.body.appendChild(Overlayer);
  10.                         }
  11.                         else {
  12.                                 Overlayer.style.display = 'block';
  13.                         }
  14.                         layerWidth = Overlayer.offsetWidth;
  15.                         layerHeight = Overlayer.offsetHeight;
  16.                         if ((pageX + this.offsetWidth + 5 + layerWidth) > viewportWidth) {
  17.                                 pageX -= 5 + layerWidth;
  18.                         }
  19.                         else {
  20.                                 pageX += this.offsetWidth + 5;
  21.                         }
  22.                         if ((pageY + this.offsetHeight + 5 + layerHeight) > viewportHeight) {
  23.                                 pageY -= 5 + layerHeight;
  24.                         }
  25.                         Overlayer.style.left = pageX + 'px';
  26.                         Overlayer.style.top = pageY + 'px';
  27.                         Overlayer.innerHTML = bigImg;
  28.                 };
  29.                 Samples[i].onmouseout = function(){
  30.                         Overlayer.style.display = 'none';
  31.                         Overlayer.innerHTML = '';
  32.                 };
  33.         }
  34. }

  35. function getViewportWidth(){
  36.         var D = document, ua = navigator.userAgent.toLowerCase(), isOpera = (ua.indexOf('opera') > -1), isIE = (!isOpera && ua.indexOf('msie') > -1), j = self.innerWidth, k = D.compatMode;
  37.         if (k || isIE) {
  38.                 j = (k == "CSS1Compat") ? D.documentElement.clientWidth : D.body.clientWidth;
  39.         }
  40.         return j;
  41. }

  42. function getViewportHeight(){
  43.         var D = document, ua = navigator.userAgent.toLowerCase(), isOpera = (ua.indexOf('opera') > -1), isIE = (!isOpera && ua.indexOf('msie') > -1), j = self.innerHeight, k = D.compatMode;
  44.         if ((k || isIE) && !isOpera) {
  45.                 j = (k == "CSS1Compat") ? D.documentElement.clientHeight : D.body.clientHeight;
  46.         }
  47.         return j;
  48. }

  49. function getPageX(el){
  50.         var D = document, box = null, parentNode = null, left = 0;
  51.         if (el.getBoundingClientRect) {
  52.                 box = el.getBoundingClientRect();
  53.                 left = box.left + Math.max(D.documentElement.scrollLeft, D.body.scrollLeft);
  54.         }
  55.         else {
  56.                 left = el.offsetLeft;
  57.                 parentNode = el.offsetParent;
  58.                 if (parentNode != el) {
  59.                         while (parentNode) {
  60.                                 left += parentNode.offsetLeft;
  61.                                 parentNode = parentNode.offsetParent;
  62.                         }
  63.                 }
  64.         }
  65.         return left;
  66. }

  67. function getPageY(el){
  68.         var D = document, box = null, parentNode = null, top = 0;
  69.         if (el.getBoundingClientRect) {
  70.                 box = el.getBoundingClientRect();
  71.                 top = box.top + Math.max(D.documentElement.scrollTop, D.body.scrollTop);
  72.         }
  73.         else {
  74.                 top = el.offsetTop;
  75.                 parentNode = el.offsetParent;
  76.                 if (parentNode != el) {
  77.                         while (parentNode) {
  78.                                 top += parentNode.offsetTop;
  79.                                 parentNode = parentNode.offsetParent;
  80.                         }
  81.                 }
  82.         }
  83.         return top;
  84. }

  85. // 调用 YPhotos('container','img');
复制代码
yaohaixiao 楼主

会武术的科学家

实习版主

帖子
2057
体力
5636
威望
45
居住地
浙江省 杭州市
发表于 2009-9-18 14:05:35 |显示全部楼层

不好意思,调整位置的时候疏忽了滚动条滑动的距离,这里是最新的代码

  1. var YHover = function(){
  2.         var D = document, ua = navigator.userAgent.toLowerCase(), isOpera = (ua.indexOf('opera') > -1), isIE = (!isOpera && ua.indexOf('msie') > -1);

  3.         return {
  4.                 photos: function(container, samples){
  5.                         var Container = D.getElementById(container), Samples = Container.getElementsByTagName(samples), i, len = Samples.length, Overlayer = null, oSelf = this;
  6.                         for (i = 0; i < len; ++i) {
  7.                                 Samples[i].onmouseover = function(){
  8.                                         var imgPath = this.parentNode.href, imgAlt = this.alt, bigImg = '<img src="' + imgPath + '" alt="' + imgAlt + '" />', pageX = oSelf.getPageX(this), pageY = oSelf.getPageY(this), viewportWidth = oSelf.getViewportWidth(), viewportHeight = oSelf.getViewportHeight(), layerWidth = 0, layerHeight = 0, xScroll = oSelf.getXScroll(), yScroll = oSelf.getYScroll();
  9.                                         if (!Overlayer) {
  10.                                                 Overlayer = D.createElement('div');
  11.                                                 Overlayer.id = 'overlayer';
  12.                                                 D.body.appendChild(Overlayer);
  13.                                         }
  14.                                         else {
  15.                                                 Overlayer.style.display = 'block';
  16.                                         }
  17.                                         layerWidth = Overlayer.offsetWidth;
  18.                                         layerHeight = Overlayer.offsetHeight;
  19.                                         if ((pageX + this.offsetWidth + 5 + layerWidth) > (viewportWidth + xScroll)) {
  20.                                                 pageX -= 5 + layerWidth;
  21.                                         }
  22.                                         else {
  23.                                                 pageX += this.offsetWidth + 5;
  24.                                         }
  25.                                         if ((pageY + this.offsetHeight + 5 + layerHeight) > (viewportHeight + yScroll)) {
  26.                                                 pageY -= 5 + layerHeight;
  27.                                         }
  28.                                         Overlayer.style.left = pageX + 'px';
  29.                                         Overlayer.style.top = pageY + 'px';
  30.                                         Overlayer.innerHTML = bigImg;
  31.                                 };
  32.                                 Samples[i].onmouseout = function(){
  33.                                         Overlayer.style.display = 'none';
  34.                                         Overlayer.innerHTML = '';
  35.                                 };
  36.                         }
  37.                 },
  38.                 getXScroll: function(){
  39.                         var j = self.pageXOffset || D.documentElement.scrollLeft || D.body.scrollLeft;
  40.                         return j;
  41.                 },
  42.                 getYScroll: function(){
  43.                         var j = self.pageYOffset || D.documentElement.scrollTop || D.body.scrollTop;
  44.                         return j;
  45.                 },
  46.                 getViewportWidth: function(){
  47.                         var j = self.innerWidth;
  48.                         var k = D.compatMode;
  49.                         if (k || isIE) {
  50.                                 j = (k == "CSS1Compat") ? D.documentElement.clientWidth : D.body.clientWidth;
  51.                         }
  52.                         return j;
  53.                 },
  54.                 getViewportHeight: function(){
  55.                         var j = self.innerHeight;
  56.                         var k = D.compatMode;
  57.                         if ((k || isIE) && !isOpera) {
  58.                                 j = (k == "CSS1Compat") ? D.documentElement.clientHeight : D.body.clientHeight;
  59.                         }
  60.                         return j;
  61.                 },
  62.                 getPageX: function(el){
  63.                         var box = null, parentNode = null, left = 0;
  64.                         if (el.getBoundingClientRect) {
  65.                                 box = el.getBoundingClientRect();
  66.                                 left = box.left + Math.max(D.documentElement.scrollLeft, D.body.scrollLeft);
  67.                         }
  68.                         else {
  69.                                 left = el.offsetLeft;
  70.                                 parentNode = el.offsetParent;
  71.                                 if (parentNode != el) {
  72.                                         while (parentNode) {
  73.                                                 left += parentNode.offsetLeft;
  74.                                                 parentNode = parentNode.offsetParent;
  75.                                         }
  76.                                 }
  77.                         }
  78.                         return left;
  79.                 },
  80.                 getPageY: function(el){
  81.                         var box = null, parentNode = null, top = 0;
  82.                         if (el.getBoundingClientRect) {
  83.                                 box = el.getBoundingClientRect();
  84.                                 top = box.top + Math.max(D.documentElement.scrollTop, D.body.scrollTop);
  85.                         }
  86.                         else {
  87.                                 top = el.offsetTop;
  88.                                 parentNode = el.offsetParent;
  89.                                 if (parentNode != el) {
  90.                                         while (parentNode) {
  91.                                                 top += parentNode.offsetTop;
  92.                                                 parentNode = parentNode.offsetParent;
  93.                                         }
  94.                                 }
  95.                         }
  96.                         return top;
  97.                 }
  98.         };
  99. }();
复制代码
帖子
117
体力
1614
威望
0
发表于 2009-9-18 14:18:14 |显示全部楼层
都是当下流行的效果,真不错
帖子
201
体力
895
威望
0
发表于 2009-9-18 15:19:09 |显示全部楼层

功能实现了,自己想优化!

http://bbs.blueidea.com/thread-2947902-1-1.html

tab做死了,和里面的内容完全没有关系,里面只是填充进去。

tab里面的样式,一时没有想法,最快的反映是在里面插表格了。把表格定义了一个css样式,这样以来造成html代码相当庞大。有好的优化方案吗。
帖子
1
体力
12
威望
0
居住地
重庆市 合川市
发表于 2009-9-18 21:55:50 |显示全部楼层
果然是很牛的人啊 这些效果实在是太实用了
帖子
16
体力
68
威望
0
居住地
广东省 深圳市
发表于 2009-9-19 17:14:13 |显示全部楼层
楼主好样的
帖子
11
体力
181
威望
0
居住地
浙江省 金华市
发表于 2009-9-19 22:38:44 |显示全部楼层

好强

好强哦非常感谢!
帖子
201
体力
895
威望
0
发表于 2009-9-21 16:28:17 |显示全部楼层

自己优化了下,请大家赐教!

请大家有时间的情况下指点一二!

 提示:您可以先修改部分代码再运行

帖子
201
体力
895
威望
0
发表于 2009-9-21 16:43:46 |显示全部楼层

去除滚动条

 提示:您可以先修改部分代码再运行

帖子
223
体力
3440
威望
0
发表于 2009-9-21 17:08:31 |显示全部楼层
帖子
518
体力
778
威望
0
居住地
湖南省 长沙市
发表于 2009-9-21 20:41:33 |显示全部楼层
先收了你 在来顶你 谢谢了。
帖子
11
体力
53
威望
0
居住地
黑龙江省 哈尔滨市
发表于 2009-9-22 12:20:38 |显示全部楼层

great

这帖子太好了,谢谢
帖子
13
体力
71
威望
0
居住地
广东省 深圳市
发表于 2009-9-23 13:12:01 |显示全部楼层
很不错的东西,已经全部收藏
帖子
20
体力
95
威望
0
居住地
广东省 深圳市
发表于 2009-9-23 15:06:09 |显示全部楼层
众里寻他千百度

哈哈

walkhard

中级会员  

帖子
48
体力
233
威望
0
居住地
天津市 南开区
发表于 2009-9-23 15:18:09 |显示全部楼层
真是不错,谢谢
好好分析学习一下~~
帖子
298
体力
739
威望
0
发表于 2009-9-25 11:22:55 |显示全部楼层
都很实用!激动……万分感谢楼主的分享!
帖子
20
体力
103
威望
0
发表于 2009-9-25 13:21:47 |显示全部楼层
这个好,要顶!

泡沫芭

中级会员

帖子
83
体力
571
威望
0
居住地
河南省 开封市
发表于 2009-9-25 13:30:04 |显示全部楼层
非常棒,收藏了。
www.abaonet.com
帖子
91
体力
555
威望
0
发表于 2009-9-25 15:05:35 |显示全部楼层
终于找到了,感谢
帖子
81
体力
286
威望
0
居住地
广西壮族自治区 来宾市
发表于 2009-9-28 23:29:20 |显示全部楼层
楼主幸苦了、我们学习了。
群30340966    http://www.077zxw.com
您需要登录后才可以回帖 登录 | 注册


Archiver|手机版|blueidea.com ( 京ICP备05002321号 )    

GMT+8, 2012-5-1 15:57 , Processed in 0.275776 second(s), 7 queries , Gzip On, Memcache On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部