zoukankan      html  css  js  c++  java
  • 利用JQuery给div按钮加上统一的动态效果

    我们有时候要在网页中做一些好看的按钮,这个时候就不能利用<input type="button" ...>,
    我们要利用div来做。
    但是由于,div本身不是按钮,如果鼠标放上去的时候,不会变成手形,在以前,我们会给每个div
    加上 onMouseover="this.style.cursor='hand'"
    但是这样做太麻烦了,因为按钮可能很多。

    如果利用JQuery,我们利用简单的JS语句就能做到。
    这样做的好处是:我们可以做到代码的封装,把JS代码保存在文件中,然后每个页面中引入这个
    js文件即可。

    JS代码如下:
    $(document).ready(function() {
        
    //Enable hover effect on the buttons.
        $('.button').hover(
            
    function() {
                $(
    this).addClass('hover');
            }

            
    function() {
                $(
    this).removeClass('hover');
            }

        );
    }
    );

    CSS代码如下:
    .button {
      width
    : 80px;
      text-align
    : center;
      margin
    : 10px;
      padding
    : 10px;
      background-color
    : #fff;
      border-top
    : 3px solid #888;
      border-left
    : 3px solid #888;
      border-bottom
    : 3px solid #444;
      border-right
    : 3px solid #444;
    }

    .hover 
    {
      cursor
    : pointer;
      background-color
    : #afa;
    }

  • 相关阅读:
    python操作adb代码
    android sdcard 权限管理策略研究
    glom模块的使用(二)
    爬虫错误汇总
    微博展开全文获取
    数据清洗之微博内容清洗
    Esxi5-管理平台vcenter5.0_数据库迁移流程
    migrating-vcenter-database-express-to-sql-2008-r2
    Centos生成SSL证书的步骤
    找到一篇关于2.4/5G信道的新介绍
  • 原文地址:https://www.cnblogs.com/davidgu/p/1535076.html
Copyright © 2011-2022 走看看