你好,这里是我的http://try.jquery.com/学习笔记:

这次来学习操作各种css。

主要对这段html元素进行操作。

<div id="all-tours">
  <h1>Guided Tours</h1>
  <ul>
    <li class="tour usa">
      <h2>New York, New York</h2>
      <span class="details">$1,899 for 7 nights</span>
      <span class="per-night"><span class="price">$275</span>/night</span>
      <button class="book">Book Now</button>
      <ul class="photos">
        <li>
          <img src="/assets/photos/newyork1.jpg">
          <span>Notre Dame de Paris</span>
        </li>
      </ul>
    </li>
    <li class="tour france" data-discount="99">
      <h2>Paris, France</h2>
      <span class="details">$1,499 for 5 nights</span>
      <span class="per-night"><span class="price">$300</span>/night</span>
      <button class="book">Book Now</button>
      <ul class="photos">
        <li>
          <img src="/assets/photos/paris3.jpg">
          <span>Brooklyn Bridge</span>
        </li>
      </ul>
    </li>
    <li class="tour uk" data-discount="149">
      <h2>London, UK</h2>
      <span class="details">$2,199 for 5 nights</span>
      <span class="per-night"><span class="price">$440</span>/night</span>
      <button class="book">Book Now</button>
      <ul class="photos">
        <li>
          <img src="/assets/photos/london.jpg">
          <span>Tower of London</span>
        </li>
      </ul>
    </li>
  </ul>
</div>

修改背景色

Let's try to make the .tour elements on this page stand out a bit more. Inside our event handler for the mouseenter event, set the background-color to #252b30 using the css() method.

要求把tour突显出来,用mouseenter事件,给这个属性添加背景色。
在app.js中,添加这样的代码:

$(document).ready(function() {
  $('.tour').on('mouseenter', function() {
    $(this).css('background-color','#252b30');
  });
});

修改字体

Let's set the font-weight to bold as well by passing in a JavaScript object to the css() method.
我先这样写了,然后得到了一大大的红色警告!

    $(this).css('font-weight', 'bold');

那么怎么改呢?
其实这里在引导我们往最高效和正确的道路上走,就是用js的对象当成参数,然后用css调用。
所以与上面的背景色一起,改成这样子就好了。

    $(this).css({'background-color':'#252b30',
                 'font-weight':'bold'});

显示隐藏属性

Let's see what the tour page would look like if we showed the .photos on mouseenter as well. Try using the show() method here to make it visible.

    $(this).find('.photos').show();

操作高亮的css样式

直接用js写一堆css还是比较费劲,所以把css都提出去,单独写css文件,然后用js来调用,才是更科学的做法。比如用addClass,removeClass,toggleClass.

  $('.tour').on('mouseover', function(){
    $(this).addClass('highlight');
  });
  $('.tour').on('mouseleave', function(){
    $(this).removeClass('highlight');
  });

添加动画,让画面跳一跳,隐身,或者转个角度

先记下来这个价格歪歪悬挂的效果吧。很好玩!

.per-night {
    opacity: 0;
    -moz-transform: rotate(20deg);
    -webkit-transform: rotate(20deg);
    transform: rotate(20deg);
    position: absolute;
    top: 0px;
    right: -13px;
}

效果图:

When the mouse first goes over the .tour element, we need to show the price per night, .per-night, and to make it stand out. Let's animate() the opacity to be 1 in our same event handler. This allows us to fade the element in.

    $(this).find('.per-night').animate({'opacity':'1'});

The price per night will now fade, but let's make it move a little as well. We can't use slideDown() for this with our animate() call, though. When the mouseenter event is triggered, animate() the top property to -14px in order to move it up a bit.
注意这里写成js对象的格式!

    $(this).find('.per-night').animate({'opacity':'1',
                                                            'top':'-14px'});

给动画加速!

Let's speed it up to run in 200ms using the 'fast' shorthand.

其实就是animate的第二个参数。可以写数字的毫秒:200,400,600之类的。其中,200和600有快捷方式,jQuery帮我们用fast和slow来表示了。如下代码所示:

    $(this).find('.per-night').animate({'opacity':'1',
                                                            'top':'-14px'}, 'fast');

动画出现了再打回原型

$(document).ready(function() {
  $('.tour').on('mouseenter', function() {
    $(this).addClass('highlight');
    $(this).find('.per-night').animate({'top': '-14px', 'opacity': '1'}, 'fast');
  });
  $('.tour').on('mouseleave', function() {
    $(this).removeClass('highlight');
    $(this).find('.per-night').animate({'top':'0px',
                                        'opacity':'0'}, 'fast');
  });
});

try.jquery-5-styling里的各种css样式操作的更多相关文章

  1. JQuery DOM操作 、属性和CSS样式操作、其他函数

    DOM操作 1.在div1内部最后追加一个节点 $("#div1").append("<img src='../01-HTML基本标签/img/Male.gif'/ ...

  2. js css样式操作代码(批量操作)

    js css样式操作代码(批量操作) 作者: 字体:[增加 减小] 类型:转载 时间:2009-10-09   用js控制css样式,能让网页达到良好的的用户体验甚至是动画的效果.并且考虑到效率.   ...

  3. jQuery 源码解析(二十六) 样式操作模块 样式详解

    样式操作模块可用于管理DOM元素的样式.坐标和尺寸,本节讲解一下样式相关,样式操作通过jQuery实例的css方法来实现,该方法有很多的执行方法,如下: css(obj)            ;参数 ...

  4. jQuery 源码解析(二十九) 样式操作模块 尺寸详解

    样式操作模块可用于管理DOM元素的样式.坐标和尺寸,本节讲解一下尺寸这一块 jQuery通过样式操作模块里的尺寸相关的API可以很方便的获取一个元素的宽度.高度,而且可以很方便的区分padding.b ...

  5. jQuery 2.0.3 源码分析 样式操作

    根据API分类 CSS addClass() jQuery.cssHooks .hasClass() .removeClass() .toggleClass() .addClass() 对元素的样式操 ...

  6. jQuery使用(二):DOM样式操作和属性操作

    DOM取值与赋值 .html() .text() .size() 1.html()方法类似原生DOM的属性innerHTML,不传入参数的时候默认为取指定元素内的HTML内容,包含前后空白文本结构,以 ...

  7. jquery加载方式,选择器,样式操作

    原生js和css不兼容,jquery已经过测试,可放心使用 https://code.jquery.com   这个网站可以下载jquery的源码,比如把源码下载到js文件夹中,文件名为jquery- ...

  8. 前端CSS样式操作

    目录 字体和文字 设置标签的宽高 字体属性 文字的属性 文字对齐 text-align 文字装饰 text-decoration 首行缩进 text-indent 背景属性 背景图片 边框 画圆 di ...

  9. jquery源码09 (6058 , 6620) css() : 样式的操作

    var curCSS, iframe, // swappable if display is none or starts with table except "table", & ...

随机推荐

  1. SQLServer 2012 已成功与服务器建立连接,但是在登录前的握手期间发生错误。 (provider: SSL Provider, error: 0 - 等待的操作过时。

    楼主用SQL Server 2012 在连接其他电脑的实例时,一直提示“已成功与服务器建立连接,但是在登录前的握手期间发生错误. (provider: SSL Provider, error: 0 - ...

  2. C语言静态函数静态变量

    C语言程序可以看成由一系列外部对象构成,这些外部对象可能是变量或函数.而内部对象是指定义在函数内部的函数参数及变量. 外部变量定义在函数之外,因此可以在许多函数中使用.由于C语言不允许在一个函数中定义 ...

  3. Android TextView 手动上下滑动

    有时候项目需求,TextView只显示若干行,其他部分隐藏,需要滑动才会显示,一般默认都是自动填充全部显示,或者手动设置高度,那样文字就显示不全,这时候可以使用下面的解决方案,代码设置显示的行数,然后 ...

  4. Android_Dialog cancle 和dismiss 区别

    AlertDialog使用很方便,但是有一个问题就是:dismiss方法和cancel方法到底有什么不同? AlertDialog继承与Dialog,现在各位看看结构图: 然后在Dialog类中找到了 ...

  5. GitHub问题之恢复本地被删除的文件

    折腾了真久,GitHub commit之后,我手痒把本地的一个文件给删了,然后一直Git pull都发现不能恢复.远程库里面还是有该文件的.就是我想将远程库的文件回到本地被删除了的位置. 特别的是,我 ...

  6. PVRTC 纹理

    iPhone的图形芯片(PowerVR MBX)对一种称为 PVRTC 的压缩技术提供的硬件支持,Apple推荐在开发iPhone应用程序时使用 PVRTC 纹理.他们甚至提供了一篇很好的技术笔记描述 ...

  7. Web模板

    http://www.iteye.com/news/26229 http://designmodo.com/admin-html-website-templates/#ixzz1mj36E4kN ht ...

  8. 学习Emacs系列教程

    emacs最简单入门,只要10分钟 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...

  9. poj 3250 Bad Hair Day(单调队列)

    题目链接:http://poj.org/problem?id=3250 思路分析:题目要求求每头牛看见的牛的数量之和,即求每头牛被看见的次数和:现在要求如何求出每头牛被看见的次数? 考虑到对于某头特定 ...

  10. debian安装jdk6

    一般用命令 apt-get install sun-java6-jdk ,会报找不到源的错误. vim /etc/apt/sources.list # 於最下方新增此行 deb http://ftp. ...