http://www.cnblogs.com/wiky/articles/gradual-change-button.html
就是看到感觉挺不错的,但换成button就做不出了,求解。

解决方案 »

  1.   

    很显然它是通过指定背景图片实现的。你指定一个button的背景如果可以的话应该就可以。
    为什么要换成button呢。这样不是挺好?
    --------------------------------------帅签分割线-------------------------------------------------
      

  2.   

    我试用了button来做,但没有效果,而且有时候提交按钮要验证表单,就想看看能不能改~
      

  3.   

    我是说你换成button了,样式脚本,是有可能也要改的
      

  4.   

    一般都是用img 或者 imgButton;  button按钮不好调样式。
      

  5.   


     $('.Button).wrapInner('<span class="hover"></span>').css('textIndent', '0').each(function() {
            //先设置<span>元素中全透明,再添加鼠标悬停事件  
            $('span.hover').css('opacity', 0).hover(function() {
                $(this).stop().fadeTo(650, 1); //渐变至不透明  
            }, function() {
                $(this).stop().fadeTo(650, 0); //渐变至全透明  
            });
        });
      

  6.   

    他的代码是给a增加一个span,然后给span绑定hover事件,慢慢控制span的透明度实现隐藏显示。如果改成button,button内嵌套span,绑定到span的hover事件在firefox下没有反应,不知道是不是firefox的buggoogle,ie都有效果,但是ie8浏览器下面会移位如果要button实现原来的效果,需要重新修改过结构。
      

  7.   

    改了下,给容器添加hover,而不是span,不过ff和ie8图片会移位,明天有空研究下css<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        
    <title>jOuery:动态渐变按钮演示--by维奇</title>
    <link rel="stylesheet" href="style.css" /><!-- 页面样式 -->
    <style> /* 纯CSS按钮 */
    .button {
    width:200px;
    height:80px;
    display:block;
    background:url(bg_button.gif) top no-repeat;
    text-indent:-9999px;border:0px;
    }
    .button:hover{
    background:url(bg_button.gif) bottom no-repeat;
    }

    /* jQuery动态渐变按钮 */
    .jsbutton {
    position:relative;
    display:block;
    width:200px;
    height:80px;
    background:url(bg_button.gif) top no-repeat;
    cursor: pointer;
    text-indent:-9999px;border:0px;
    }
    .jsbutton span.hover {
    position: absolute;
    display: block;
    width:200px;
    height:80px;
    background:url(bg_button.gif) bottom no-repeat;
    text-indent:-9999px;opacity:0;filter:alpha(opacity=0);left:0px;top:0px;
    }


    /* 扩展应用按钮样式 */
    .viewbutton,.viewbutton span.hover,.downloadbutton,.downloadbutton span.hover{
    display: block;
    width:120px;
    height:42px;
    background-image:url(vd_bg_button.gif);
    text-indent:-9999px;border:0px;
    }
    .viewbutton {
    float: left;
    position:relative;
    background-position: top left;border:0px;
    }
    .viewbutton span.hover{
    position: absolute;
    background-position: bottom left;left:0px;top:0px;
    }
    .downloadbutton {
    float: left;
    position:relative;
    background-position: top right;
    }
    .downloadbutton span.hover{
    position: absolute;
    background-position: bottom right;left:0px;top:0px;

    }

    </style>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $('.jsbutton,.viewbutton,.downloadbutton').wrapInner('<span class="hover"></span>').css('textIndent','0').find('span').css('opacity',0).end().hover(function(){$('span',this).fadeTo(650,1);},function(){$('span',this).fadeTo(650,0);});
    });
    </script>
    </head>
    <body>
    <div id="header">
        <div id="header_nav">
         <div class="fleft">
                <a class="top_home" title="首页" href="http://wiky.000a.biz/">HOME</a>
                <a class="top_blog" title="博客" href="http://wiky.cnblogs.com/">BLOG</a>       
          </div>
            <div class="fright">
             <a class="top_about" title="关于作者" href="http://www.cnblogs.com/wiky/articles/about.html">ABOUT</a>
            </div>
            </div>
        </div>
        <div id="content">
         <h1>jOuery动态渐变按钮</h1>

    <p>这是一个演示页面,您可以点击 <a href="http://www.cnblogs.com/wiky/articles/gradual-change-button.html">查看原文</a></p>

    <hr /> <h2>纯CSS效果 <small>| xhtml + css</small></h2>
    <p class="fcenter"><a href="http://wiky.cnblogs.com/" class="button">前端档案</a></p>
             <p class="fcenter"><button class="button">前端档案</button></p>
    <br/>
            
    <h2>jQuery动态渐变效果 <small>| xhtml + css + javascript</small></h2>
    <p class="fcenter"><a href="http://wiky.cnblogs.com/" class="jsbutton">前端档案</a></p>
          <p class="fcenter"><button class="jsbutton">前端档案</button></p>       
    <br/>
            
    <h2>扩展效果应用</h2>
    <p class="vdbutton">
    <a href="http://wiky.000a.biz/demo/0421/gradual-change-button.html" class="viewbutton">查看演示</a>
    <a href="gcb_download.rar" class="downloadbutton">下载源码</a><br/>
    <button  class="viewbutton">查看演示</button><button class="downloadbutton">下载源码</button>
            </p>
    </div>
        <div id="footer">
          <div class="fleft">Copyright &copy; 2010 &nbsp;<a target="_blank" href="http://wiky.cnblogs.com/">Marco Wiky</a></div>
             <div class="fright"><a target="_blank" href="http://wiky.cnblogs.com/">维奇-前端档案</a></div>
    </div>
    </body>
    </html>
      

  8.   

    大概修改了下样式,将a相对定位,span绝对定位全部改为静态的,要不button内嵌入span在Firefox,IE8下会出现span没有覆盖button的问题。IE8的话去掉XHTML申明也可以解决span不覆盖的问题,ff去掉xhtml申明也没得,不知道搞什么飞机。改为静态的情况下,ff下button嵌套span还是会出现span左边出现3px,顶部2px空白的问题,用代码重新设置了下span的margin<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        
        <title>jOuery:动态渐变按钮演示--by维奇</title>
        <link rel="stylesheet" href="style.css" /><!-- 页面样式 -->
        <style>        /* 纯CSS按钮 */
            .button {
                width:200px;
                height:80px;
                display:block;
                background:url(bg_button.gif) top no-repeat;
                text-indent:-9999px;border:0px;
            }
            .button:hover{
                background:url(bg_button.gif) bottom no-repeat;
            }
            
            /* jQuery动态渐变按钮 */
            .jsbutton {
                display:block;
                width:200px;
                height:80px;
                background:url(bg_button.gif) top no-repeat;
                cursor: pointer;
                text-indent:-9999px;
                border:0px;border:0px;padding:0px;
            }    
            .jsbutton span.hover {
                display: block;
                width:200px;
                height:80px;
                background:url(bg_button.gif) bottom no-repeat;
                text-indent:-9999px;
            }
            
            
            /* 扩展应用按钮样式 */
            .viewbutton,.viewbutton span.hover,.downloadbutton,.downloadbutton span.hover{
                display: block;
                width:120px;
                height:42px;background-color:transparent;
                background-image:url(vd_bg_button.gif);
                text-indent:-9999px;border:0px;border:0px;padding:0px;
            }
            .viewbutton {
                float: left;
                background-position: top left;
            }
            .viewbutton span.hover{
                background-position: bottom left;
            }
            .downloadbutton {
                float: left;
                background-position: top right;
            }
            .downloadbutton span.hover{   
                background-position: bottom right;
                
            }
        </style>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('.jsbutton,.viewbutton,.downloadbutton').wrapInner('<span class="hover"></span>').find('span')
                .css({
                 opacity: 0
    ////////////////Fix firefox button -> span has magin problem
                 , "margin-top": function () { if (this.parentNode.tagName=='BUTTON'&& /firefox/i.test(navigator.userAgent)) return -2; return 0; }
                 , "margin-left": function () { if (this.parentNode.tagName=='BUTTON'&& /firefox/i.test(navigator.userAgent)) return -3; return 0; } 
                 })
                .end()
                .hover(function () { $('span', this).stop().fadeTo(650, 1); }, function () { $('span', this).stop().fadeTo(650, 0); });
            });
        </script></head>
    <body>
        <div id="header">
        <div id="header_nav">
            <div class="fleft">
                <a class="top_home" title="首页" href="http://wiky.000a.biz/">HOME</a>
                <a class="top_blog" title="博客" href="http://wiky.cnblogs.com/">BLOG</a>       
             </div>
            <div class="fright">            <a class="top_about" title="关于作者" href="http://www.cnblogs.com/wiky/articles/about.html">ABOUT</a>
            </div>
            </div>
        </div>
        <div id="content">
            <h1>jOuery动态渐变按钮</h1>
            
            <p>这是一个演示页面,您可以点击 <a href="http://www.cnblogs.com/wiky/articles/gradual-change-button.html">查看原文</a></p>        
            <hr />        <h2>纯CSS效果 <small>| xhtml + css</small></h2>
            <p class="fcenter"><a href="http://wiky.cnblogs.com/" class="button">前端档案</a></p>
                <p class="fcenter"><button class="button">前端档案</button></p>
            <br/>
            
            <h2>jQuery动态渐变效果 <small>| xhtml + css + javascript</small></h2>            <p class="fcenter"><a href="http://wiky.cnblogs.com/" class="jsbutton">前端档案</a></p>
                     <p class="fcenter"><button class="jsbutton">前端档案</button></p>       
            <br/>
            
            <h2>扩展效果应用</h2>            
            <p class="vdbutton">
                <a href="http://wiky.000a.biz/demo/0421/gradual-change-button.html" class="viewbutton">查看演示</a>
                <a href="gcb_download.rar" class="downloadbutton">下载源码</a></p>        <p class="vdbutton">
                <button  class="viewbutton">查看演示</button>
                <button class="downloadbutton">下载源码</button>
            </p>
        </div>
        <div id="footer">
             <div class="fleft">Copyright &copy; 2010 &nbsp;<a target="_blank" href="http://wiky.cnblogs.com/">Marco Wiky</a></div>         <div class="fright"><a target="_blank" href="http://wiky.cnblogs.com/">维奇-前端档案</a></div>
        </div>
    </body>
    </html>